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.

Chapter 24 Attributesaffirm the default in non-ambiguous cases). Thus, typically, attribute-target-specifiers can be omittedexcept at the global level. The potentially ambiguous contexts are resolved as follows:• An attribute specified on a delegate declaration can apply either to the delegate being declared or to itsreturn value. In the absence of an attribute-target-specifier, the attribute applies to the delegate. Thepresence of the type attribute-target-specifier indicates that the attribute applies to the delegate; thepresence of the return attribute-target-specifier indicates that the attribute applies to the return value.• An attribute specified on a method declaration can apply either to the method being declared or to itsreturn value. In the absence of an attribute-target-specifier, the attribute applies to the method. Thepresence of the method attribute-target-specifier indicates that the attribute applies to the method; thepresence of the return attribute-target-specifier indicates that the attribute applies to the return value.• An attribute specified on an operator declaration can apply either to the operator being declared or to itsreturn value of this declaration. In the absence of an attribute-target-specifier, the attribute applies to theoperator. The presence of the method attribute-target-specifier indicates that the attribute applies to theoperator; the presence of the return attribute-target-specifier indicates that the attribute applies to thereturn value.• An attribute specified on an event declaration that omits event accessors can apply to the event beingdeclared, to the associated field (if the event is not abstract), or to the associated add and removemethods. In the absence of an attribute-target-specifier, the attribute applies to the event declaration.The presence of the event attribute-target-specifier indicates that the attribute applies to the event; thepresence of the field attribute-target-specifier indicates that the attribute applies to the field; and thepresence of the method attribute-target-specifier indicates that the attribute applies to the methods.• An attribute specified on a get accessor declaration for a property or indexer declaration can apply eitherto the associated method or to its return value. In the absence of an attribute-target-specifier, theattribute applies to the method. The presence of the method attribute-target-specifier indicates that theattribute applies to the method; the presence of the return attribute-target-specifier indicates that theattribute applies to the return value.• An attribute specified on a set accessor for a property or indexer declaration can apply either to theassociated method or to its lone implicit parameter. In the absence of an attribute-target-specifier, theattribute applies to the method. The presence of the method attribute-target-specifier indicates that theattribute applies to the method; the presence of the param attribute-target-specifier indicates that theattribute applies to the parameter.• An attribute specified on an add or remove accessor declaration for an event declaration can apply eitherto the associated method or to its lone parameter. In the absence of an attribute-target-specifier, theattribute applies to the method. The presence of the method attribute-target-specifier indicates that theattribute applies to the method; the presence of the param attribute-target-specifier indicates that theattribute applies to the parameter.An implementation may accept other attribute target specifiers, the purpose of which is implementationdefined.However, an implementation that does not recognize such a target, shall issue a warning.By convention, attribute classes are named with a suffix of Attribute. An attribute-name of the form typenamemay either include or omit this suffix. If an attribute class is found both with and without this suffix,an ambiguity is present, and a compile-time error shall be issued. If the attribute-name is spelled such thatits right-most identifier is a verbatim identifier (§9.4.2), then only an attribute without a suffix is matched,thus enabling such an ambiguity to be resolved. [Example: The exampleusing System;[AttributeUsage(AttributeTargets.All)]public class X: Attribute{}[AttributeUsage(AttributeTargets.All)]public class XAttribute: Attribute{}309

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

Saved successfully!

Ooh no, something went wrong!