X hits on this document

1121 views

0 shares

0 downloads

0 comments

318 / 396

Chapter ‎18   Unsafe code

attribute-arguments: (   positional-argument-listopt   ) (   positional-argument-list   ,   named-argument-list   ) (   named-argument-list   )

positional-argument-list: positional-argument positional-argument-list   ,   positional-argument

positional-argument: attribute-argument-expression

named-argument-list: named-argument named-argument-list   ,   named-argument

named-argument: identifier   =   attribute-argument-expression

attribute-argument-expression: expression

An attribute consists of an attribute-name and an optional list of positional and named arguments. The positional arguments (if any) precede the named arguments. A positional argument consists of an attribute-argument-expression; a named argument consists of a name, followed by an equal sign, followed by an attribute-argument-expression, which, together, are constrained by the same rules as simple assignment. The order of named arguments is not significant.

The attribute-name identifies an attribute class. If the form of attribute-name is type-name then this name must refer to an attribute class. Otherwise, a compile-time error occurs. The example

class Class1 {}

[Class1] class Class2 {}// Error

results in a compile-time error because it attempts to use Class1 as an attribute class when Class1 is not an attribute class.

Certain contexts permit the specification of an attribute on more than one target. A program can explicitly specify the target by including an attribute-target-specifier. When an attribute is placed at the global level, a global-attribute-target-specifier is required. In all other locations, a reasonable default is applied, but an attribute-target-specifier can be used to affirm or override the default in certain ambiguous cases (or to just affirm the default in non-ambiguous cases). Thus, typically, attribute-target-specifiers can be omitted except at the global level. The potentially ambiguous contexts are resolved as follows:

An attribute specified at global scope can apply either to the target assembly or the target module. No default exists for this context, so an attribute-target-specifier is always required in this context. The presence of the assembly attribute-target-specifier indicates that the attribute applies to the target assembly; the presence of the module attribute-target-specifier indicates that the attribute applies to the target module.

An attribute specified on a delegate declaration can apply either to the delegate being declared or to its return value. In the absence of an attribute-target-specifier, the attribute applies to the delegate. The presence of the type attribute-target-specifier indicates that the attribute applies to the delegate; the presence 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 its return value. In the absence of an attribute-target-specifier, the attribute applies to the method. The presence of the method attribute-target-specifier indicates that the attribute applies to the method; the presence of the return

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.305

Document info
Document views1121
Page views1121
Page last viewedTue Jan 17 05:43:35 UTC 2017
Pages396
Paragraphs9401
Words133190

Comments