Annotating Types and Members

Thus far we have covered the general benefits of attributes and explored global attributes. Attributes can be applied at the type, method, property, and field levels, too.

The general syntax for applying attributes at a lower level of granularity is similar to using global attributes. Non-global attributes do not use the Assembly: prefix. Let's take a look at some specific attributes that can be applied to types (like classes) and members of types.

Adding Type Attributes

Attributes can be applied to types as well as members of types. The AttributeUsageAttribute is used to define an attribute class and the AttributeTargets enumeration flag passed to that attribute determines how a particular attribute can be used and ...

Get Visual Basic® .NET Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.