Conditional Attribute Classes
From RemObjects Software
This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.
A conditional attribute class is defined as an attribute class decorated with the Conditional attribute (see Special Attributes). The Conditional attribute indicates a condition by testing a conditional compilation symbol. Attribute specifications of a conditional attribute class are either included or omitted depending on whether this symbol is defined at the point of specification.
Example:
{$DEFINE DEBUG} uses System.Diagnostics; type [Conditional("DEBUG")] TestAttribute = public class(Attribute) ... [Test] MyClass = class ...
The above declares the attribute class TestAttribute as a conditional attribute class and subsequently applies a Test attribute to MyClass. Since the conditional compilation symbol DEBUG is defined, retrieving the attributes applied to MyClass at runtime will result in an instance of the TestAttribute class. If the symbol DEBUG had not been defined, then retrieving the attributes applied to MyClass at runtime would not result in an instance of the TestAttribute class.
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. Check the following example:
uses System.Diagnostics; type [Conditional(“DEBUG”)] TestAttribute = public class(Attribute) ... {$DEFINE DEBUG} [Test] // TestAttribute is included Class1 = class ... {$UNDEF DEBUG} [Test] // TestAttribute is excluded Class2 = class ...
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.
See Also
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Language | Feature
