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!

Using Attributes

Attributes can be placed on most any declaration (though a specific attribute might restrict the types of declarations on which it is valid). Syntactically, an attribute is specified by placing the name of the attribute, enclosed in square brackets, in front of the declaration of the entity to which it applies. For example, a class with the predefined attribute comimport is declared like this:

[comimport] public class MyComimportClass { ... }

Many attributes have parameters, which can be either positional (unnamed) or named. Any positional parameters must be specified in a certain order and cannot be omitted; named parameters are optional and can be specified in any order. Positional parameters are specified first. For example, these three attributes are equivalent:

[dllimport("user32.dll", SetLastError=false, ExactSpelling=false)]
[dllimport("user32.dll", ExactSpelling=false, SetLastError=false)]
[dllimport("user32.dll")]

The first parameter, the DLL name, is positional and always comes first; the others are named. In this case, both named parameters default to false, so they can be omitted (refer to the individual attribute's documentation for information on default parameter values).

More than one attribute can be placed on a declaration, either separately or within the same set of brackets:

bool AMethod([in][out]ref double x);
bool AMethod([out][in]ref double x);
bool AMethod([in,out]ref double x);

Some attributes can be specified more than once for a given entity. An example of such a multi-use attribute is conditional:

[conditional("DEBUG"), conditional("TEST1")] void TraceMethod() {...}

See Also

Introduction to Attributes | Global Attributes | Creating Custom Attributes | Retrieving Attribute Information