Now here’s a trick that I didn’t know - you can use the [Conditional] attribute to suppress a method unless a given symbol is defined at compile time.

From the MSDN documentation:

Applying ConditionalAttribute to a method indicates … the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with ConditionalAttribute is defined.

Mostly of use when you’re writing logging and other diagnostic code - indeed, major use in the framework seems to be in the Debug and Trace classes.

See details on MSDN at http://msdn2.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx

Comments

blog comments powered by Disqus
Next Post
The End of an Era  10 Apr 2008
Prior Post
Renaming WPF Windows  07 Apr 2008
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
Archives
April 2008
2008