I am busy making some optimizations to a app of mine, what is the cleanest way to check if the app is in DEBUG or RELEASE
static class Program
{
public static bool IsDebugRelease
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
}
Though, I tend to agree with itowlson.
Personally I don't like the way #if DEBUG
changes the layout. I do it by creating a conditional method that is only called when in debug mode and pass a boolean by reference.
[Conditional("DEBUG")]
private void IsDebugCheck(ref bool isDebug)
{
isDebug = true;
}
public void SomeCallingMethod()
{
bool isDebug = false;
IsDebugCheck(ref isDebug);
//do whatever with isDebug now
}
At compile time or runtime? At compile time, you can use #if DEBUG
. At runtime, you can use [Conditional("DEBUG")]
to indicate methods that should only be called in debug builds, but whether this will be useful depends on the kind of changes you want to make between debug and release builds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With