ASP.NET Cafe
new tricks every week

HOWTO: Use Conditional attribute to make custom actions during debug

Sunday, 6 January 2008 08:11 by dmitriy

Sometimes we need to make some write to logs, trace, and maybe limit some features during debug. It's good to know that in debug mode we have precompiler identifier DEBUG is set. So, first of all you can try #if #endif construction. IMHO, it's not very good to use #if directive. If there are something better. Conditional attribute. It can be applied to any method that returns void. Why void? Because the method call ignored if the condition is not fulfilled. The method can be static or not.

[Conditional("DEBUG")]
static void DebugMethod()
{
}

So, this is the best way to make some job in DEBUG configuration. Also, it can be used to make different build configurations.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   C#
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading