I have a variable(i.e bool releaseMode = false;
)
I want the value of the variable to be set based on whether we are in release mode(releaseMode = true;
) else debug mode(releaseMode = false;
)
Asked
Active
Viewed 606 times
2

shahab jani
- 88
- 5
1 Answers
2
From your question, you can use that:
/// <summary>
/// Indicate if the executable has been generated in debug mode.
/// </summary>
static public bool IsDebugExecutable
{
get
{
bool isDebug = false;
CheckDebugExecutable(ref isDebug);
return isDebug;
}
}
[Conditional("DEBUG")]
static private void CheckDebugExecutable(ref bool isDebug)
=> isDebug = true;
Of course you can swap name to:
IsReleaseExecutable
return !isDebug;
This approach implies that all code is compiled. Thus any code can be executed depending on this flag as well as any other behavior parameter concerning the user or the program, such as for example the activation or the deactivation of a debugging and tracing engine. For example:
if ( IsDebugExecutable || UserWantDebug ) DoThat();
Else a preprocessor directive like this:
-
what about this code : #if DEBUG releaseMode = false; #else releaseMode = true; #endif – shahab jani Jun 04 '21 at 08:31
-
1As you want. Choose the method that works best for you, which is the most appropriate for you and for the context. Choose what you find clearest, cleanest, most efficient, and most maintainable. Personally after reading and testing several things I chose the suggested code I found the most tidy. – Jun 04 '21 at 08:36