Conditional attribute classes
An attribute class (§17.1) decorated with one or more Conditional attributes is a conditional attribute class. A conditional attribute class is thus associated with the conditional compilation symbols declared in its Conditional attributes. This example: using System; declares TestAttribute as a conditional attribute class associated with the conditional compilations symbols ALPHA and BETA. Attribute specifications (§17.2) of a conditional attribute are included if one or more of its associated conditional compilation symbols is defined at the point of specification, otherwise the attribute specification is omitted. It is important to note that the inclusion or exclusion of an attribute specification of a conditional attribute class is controlled by the conditional compilation symbols at the point of the specification. In the example File test.cs: using System; [Conditional("DEBUG")] public class TestAttribute: Attribute {} File class1.cs: #define DEBUG [Test] // TestAttribute is specified class Class1 {} File class2.cs: #undef DEBUG [Test] // TestAttribute is not specified class Class2 {} the classes Class1 and Class2 are each decorated with attribute Test, which is conditional based on whether or not DEBUG is defined. Since this symbol is defined in the context of Class1 but not Class2, the specification of the Test attribute on Class1 is included, while the specification of the Test attribute on Class2 is omitted.
|