Conditional Debug mode

Sometimes we have to implement code that is only meant to work for us as developers and not the our clients. That is when conditional debug comes to play. Using conditional debug it is possible to only allow some functions to be called only if the project is running in debug mode.

I found it useful on the following scenarios:

  • Impersonation – change my context to a specific user contex.
  • Tracing/Profiling
  • Testing

[Conditional("DEBUG")]

  public void OnlyRunIfUnderDebug(string person)
       {
           //replace context with person's arguments context
           //profiling
           //testing
           //etc
       }