C# - Reflection에 대한 고찰

C# 프로그래밍 씬에서 가장 흔한 오해중 하나는 “Reflection은 느리니까 자제해야 한다.” 라는 것. 처음엔 그냥 그런가보다 했다. C#에 대한 이해도가 많이 부족했으니. 하지만 필요에 의해 Reflection을 사용하게 됐고, 그것 없이 C# 프로그래밍을 하기에 불편함에 이르렀다. 제대로 이해하고 적절히 사용해야 할 때가 온 것이다. 깊게 파보고, 프로파일링 - 최적화 해보고. 그 과정들을 통해 지금은 올바른 Reflection 사용은 현대적이고 발전된 코드를 작성할 수 있다. 라고 생각하게 됐다. 느리다는 것 처리 시간이 오래 걸린다....

September 25, 2020 · 3 min · 587 words · penspanic

C# 람다 내부 구현

마법은 없다. Lambda를 컴파일러가 어떤식으로 구현하는지 알아둘 필요가 있다. public static class LambdaExample { public static void Run() { int localInt = 123456789; string localString = "LocalString"; ActionRunner(() => { Console.WriteLine($"{localInt}, {localString}"); }); } private static void ActionRunner(Action action) { action?.Invoke(); } } Decompiled il source // Type: CSharpExamples.LambdaExample // Assembly: CSharpExamples, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null // MVID: B420F7F8-9269-4798-8719-2A8ECDC7FBCA // Location: /Users/geunheepark/Projects/private/CSharpExamples/CSharpExamples/bin/Debug/netcoreapp3.1/CSharpExamples.dll // Sequence point data from /Users/geunheepark/Projects/private/CSharpExamples/CSharpExamples/bin/Debug/netcoreapp3.1/CSharpExamples.pdb .class public abstract sealed auto ansi beforefieldinit CSharpExamples....

September 20, 2020 · 4 min · 725 words · penspanic

Unity - Assembly Definition

요약 Assembly를 나누어, 모듈별 의존성을 명확하게 관리하고, 컴파일 시간을 줄인다. 내용 기본 Unity 컴파일 시스템은 2개의 Assembly를 만들어낸다. 프로젝트 안 소스파일들이 기본적으로 Assembly-CSharp에 포함되고, “Editor” 란 이름의 Directory안의 소스파일들은 Assembly-Csharp-Editor에 포함된다. 결국, 특정 소스코드를 1줄만 수정을 해도 그 소스코드가 포함된 어셈블리를 다시 컴파일 해야 한다. 이 과정에서 프로젝트가 커지고, 모듈이 많이 붙을 수록 컴파일 시간이 길어진다. 이 문제를 해결할 수 있는 기능이 Unity 2018에 추가된 Assembly Definition 기능이다. 스크립트 컴파일 및 어셈블리 정의 파일(Script compilation and assembly definition files) - Unity 매뉴얼...

September 18, 2020 · 1 min · 101 words · penspanic