ARTICLE AD BOX
Consider the folllowing class:
public class Foo { public const bool DebugThis = false; public void Method() { if (DebugThis) { System.Console.WriteLine("Debugging..."); // compiler warning: "unreachable code detected" // answers should not focus on the fact that this is a WriteLine. In genenral, there is some code that happens only if DebugThis is true. } } }There are ways to silence that warning. I don't like any of the ones I am aware of.
Putting in #pragma is clunky, and you have to have two of them. Furthermore, there may be multiple DebugThis checks at different places in the code, which would cause the number of #pragma to go up.
I don't want to in general disable "unreachable code detected". Sometimes it's useful.
What I really do want is to tell the compiler that it should not consider the value of DebugThis for purposes of warnings. For that purpose only, it should consider that DebugThis might be true or false.
Is there a way to do that?
8
