I would like to add some C# "debug only" code that only runs if the person debugging requests it. In C++, I used to do something similar to the following:
void foo() { // ... #ifdef DEBUG static bool s_bDoDebugOnlyCode = false; if (s_bDoDebugOnlyCode) { // Debug only code here gets executed when the person debugging // manually sets the bool above to true. It then stays for the rest // of the session until they set it to false. } #endif // ... } I can't do exactly the same in C# since there is no local statics.
Question: What is the best way to accomplish this in C#?
- Should I use a private class static field with C# preprocessor directives (
#if/#endif DEBUG)? - Should I use the Conditional attribute (to hold the code), and then a private class static field (not surrounded by C# preprocessor directives
#if/#endif DEBUG?). - Something else?