There is one very important thing you need to know about
this object and all its methods: You are writing code in invisible ink!
Now I am sure you are going, "that's it, Rayburn has finally gone off the
deep end." But hear me out! Consider Listing 1.
Listing 1 - A simple System.Diagnostics.Debug call
class Program
{
static void Main(string[] args)
{
Debug.Assert(true, "Vanishing code!");
}
}
Simple enough yes? Well, let us compile this in Debug
mode and see what Lutz's Reflector
has to say about it.
Listing 2 - Reflector disassembly of Debug mode
compile
Yep, just what you would expect. I am sure now you are
totally convinced I have lost it. But watch, swap this to Release mode
and…
Listing 3 - Reflector disassembly of Release mode
compile
instantly vanishing code! So the key here is that you
can use the Debug object, and all its methods, with reckless abandon and, when
you actually compile a release build, all of it goes away.