13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONLet Name be the identifier of the named-argument Arg. If Name does not identify a non-static public readwritefield or property on O, then an exception is thrown.Let Value be the result of evaluating the attribute-argument-expression of Arg.If Name identifies a field on O, then set this field to the value Value.Otherwise, Name identifies a property on O. Set this property to the value Value.The result is O, an instance of the attribute class T that has been initialized with the positional-argumentlistP and the named-argument-list N.24.4 Reserved attributesA small number of attributes affect the language in some way. These attributes include:• System.AttributeUsageAttribute (§24.4.1), which is used to describe the ways in which anattribute class can be used.• System.ConditionalAttribute (§24.4.2), which is used to define conditional methods.• System.ObsoleteAttribute (§24.4.3), which is used to mark a member as obsolete.24.4.1 The AttributeUsage attributeThe attribute AttributeUsage is used to describe the manner in which the attribute class can be used.A class that is decorated with the AttributeUsage attribute must derive from System.Attribute, eitherdirectly or indirectly. Otherwise, a compile-time error occurs.[Note: For an example of using this attribute, see §24.1.1. end note]24.4.2 The Conditional attributeThe attribute Conditional enables the definition of conditional methods. The Conditional attributeindicates a condition by testing a conditional compilation symbol. Calls to a conditional method are eitherincluded or omitted depending on whether this symbol is defined at the point of the call. If the symbol isdefined, the call is included; otherwise, the call is omitted.A conditional method is subject to the following restrictions:• The conditional method must be a method in a class-declaration or struct-declaration. A compile-timeerror occurs if the Conditional attribute is specified on an interface method.• The conditional method must have a return type of void.• The conditional method must not be marked with the override modifier. A conditional method may bemarked with the virtual modifier, however. Overrides of such a method are implicitly conditional,and must not be explicitly marked with a Conditional attribute.• The conditional method must not be an implementation of an interface method. Otherwise, a compiletimeerror occurs.In addition, a compile-time error occurs if a conditional method is used in a delegate-creation-expression.[Example: The example#define DEBUG312

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!