I've started to use a define class like so:
internal sealed class Defines
{
/// <summary>
/// This constant is set to true iff the define DEBUG is set.
/// </summary>
public const bool Debug =
#if DEBUG
true;
#else
false;
#endif
}
The advantages I see is:
Possible disadvantage I see:
Compiler can't optimize unused code if the Defines class is in another assembly. Which is why I have made internal.
Am I missing any other disadvantages?
[Edit] Typical examples of usage:
private readonly Permissions _permissions = Defines.Debug ? Permissions.NewAllTrue()
: Permissions.NewAllFalse();
Or:
var str = string.Format(Defines.Debug ? "{0} {1} ({2})" : "{0} {1}", actual, text, advance);
A Debug value indicates a debug configuration. When you start the app (press the green arrow or F5) in a debug configuration, you start the app in debug mode, which means you are running your app with a debugger attached.
By default, Debug includes debug information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled. As far as conditional compilation goes, they each define different symbols that can be checked in your program, but they are language-specific macros.
Visual debugging provides the Visual Debug view for you to interact with your COBOL or PL/I debug session. With this view, you can visualize the stack trace, set breakpoints, and run to a selected call path.
I see at least one big disadvantage: if Debug
is false, this code will cause a warning:
if (Debug)
Console.WriteLine("Debug");
Because the compiler will detect that the condition is never met, so the Console.WriteLine
call is unreachable.
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