Last active
January 30, 2021 14:18
-
-
Save hsytkm/9959e3be1c98f8056f0ec960085c40bc to your computer and use it in GitHub Desktop.
How to write "#if DEBUG"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// これでも問題ないけど、インテリセンスが効かなくてダサい | |
#if DEBUG | |
System.Console.WriteLine("Debug build dane."); | |
#else | |
System.Console.WriteLine("Release build dane."); | |
#endif | |
// こちらだとインテリセンスが効く | |
// しかも const 定義の if 文は IL で消してくれる (ILSpyで確認済み) | |
if (AssemblyState.IsDebugBuild) | |
{ | |
System.Console.WriteLine("Debug build dayo."); | |
} | |
else | |
{ | |
System.Console.WriteLine("Release build dayo."); | |
} | |
static class AssemblyState | |
{ | |
public const bool IsDebugBuild = | |
#if DEBUG | |
true; | |
#else | |
false; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment