Skip to content

Instantly share code, notes, and snippets.

@hsytkm
Last active January 30, 2021 14:18
Show Gist options
  • Save hsytkm/9959e3be1c98f8056f0ec960085c40bc to your computer and use it in GitHub Desktop.
Save hsytkm/9959e3be1c98f8056f0ec960085c40bc to your computer and use it in GitHub Desktop.
How to write "#if DEBUG"
// これでも問題ないけど、インテリセンスが効かなくてダサい
#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