NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

17.2 Attribute specification

An attribute is a piece of additional declarative information that is specified for a declaration. Attributes can be specified for type-declarations, class-member-declarations, interface-member-declarations, enum-member-declarations, property-accessor-declarations and formal-parameter declarations.

Attributes are specified in attribute sections. Each attribute section is surrounded in square brackets, with multiple attributes specified in a comma-separated lists. The order in which attributes are specified, and the manner in which they are arranged in sections is not significant. The attribute specifications [A][B], [B][A], [A, B], and [B, A] are equivalent.

attributes:
attribute-sections
attribute-sections:
attribute-section
attribute-sections attribute-section
attribute-section:
[ attribute-list ]
[ attribute-list ,]
attribute-list:
attribute
attribute-list
, attribute
attribute:
attribute-name attribute-argumentsopt
attribute-name:
reserved-attribute-name
type-name
attribute-arguments:
( positional-argument-list )
( 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.

The attribute-name identifies either a reserved attribute or 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

is in error because it attempts to use Class1, which is not an attribute class, as an attribute class.

It is an error to use a single-use attribute class more than once on the same entity. The example

[AttributeUsage(AttributeTargets.Class)]
public class HelpStringAttribute: System.Attribute
{
   string value;
   public HelpStringAttribute(string value) {
      this.value = value;
   }
   public string Value { get {…} }
}
[HelpString("Description of Class1")]
[HelpString("Another description of Class1")]
public class Class1 {}

is in error because it attempts to use HelpString, which is a single-use attribute class, more than once on the declaration of Class1.

An expression E is an attribute-argument-expression if all of the following statements are true: