Attributes Specification

Attribute specification describes setting predefined attributes to a declaration. Attributes are declared using attribute sections. The attribute section consists of square brackets that frame a list of attributes separated with commas. The order of setting attributes does not matter.

global-attributes:

global-attribute-sections

global-attribute-sections:

global-attribute-section

global-attribute-sections  global-attribute-section

global-attribute-section:

[   global-attribute-target-specifier   attribute-list   ]

global-attribute-target-specifier:

global-attribute-target   :

global-attribute-target:

Assembly

Module

attributes:

attribute-sections

attribute-sections:

attribute-section

attribute-sections   attribute-section

attribute-section:

[   attribute-target-specifieropt  attribute-list   ]

[   attribute-target-specifieropt  attribute-list  ,  attribute-target-specifieropt  attribute-list   ]

attribute-target-specifier:

    attribute-target   :

attribute-target:

Field

Event

Method

Param

Property

Return

Type

attribute-list:

attribute

attribute-list   ,   attribute

attribute:

attribute-name   attribute-argumentsopt

attribute-name:

type-name

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 description consists of its name and optional list of position and named parameters. Position parameters (if there are any) should stand before the named ones. The order of named attributes does not matter. Attribute name identifies the corresponding attribute class. If there is no attribute class with this name, a compile error occurs.

The specifier of the attribute target showing the relation of the attribute can also be specified for the attribute.

NOTE. If the name of the attribute target specifier matches the keyword, @ character must be specified before.

By agreement, attribute classes' names end with the Attribute suffix. An attribute name may include this suffix or it may be omitted. A compile error occurs if there are attribute classes that correspond to an attribute name both with suffix and without suffix.

Applying a one-time attribute to a declaration more than once is a compilation error.

Expression E can be used as a parameter value if all of the following conditions are satisfied:

Example

An example of using a custom attribute class is given in description of attribute parameters.

See also:

Attributes