Wednesday, March 24, 2010

The Conditional Attribute

This attribute is in the namespace System.Diagnostics. It is used to execute a method if a specific constant is defined in the program. For example:
[Conditional(“MYCONSTANT”)]
Public void MyMethod(string s) { }
MyMethod is only executed if the constant MYCONSTANT is defined in the program with a preprocessor directive:
#define MYCONSTANT
If the constant is not defined, the execution resumes and the attribute are ignored. The target method must be of the void type.

No comments:

Post a Comment