共用方式為


Attributes Overview in Visual Basic 

Attributes are descriptive tags that provide additional information about programming elements such as types, fields, methods, and properties. Other applications, such as the Visual Basic compiler, can refer to the extra information in attributes to determine how these items can be used.

Attributes and Metadata

Attributes are saved with the metadata of Visual Basic assemblies. Metadata is information that describes every element managed by the runtime. This includes information required for debugging and garbage collection, as well as security attributes, marshaling data, extended class and member definitions, version binding, and any other information the runtime requires.

With attributes, you specify the metadata in much the same way as you use keywords like Public and Private to provide information about access levels. However, unlike keywords, most attributes are not language-specific. Using attributes, you can extend the capabilities of the Visual Basic language without requiring changes to the compiler.

The .NET Framework and the Visual Basic language define many useful attributes, and you can define your own custom attributes that are meaningful to your application. Custom attributes are based on the System.Attribute class, and they use the AttributeUsageAttribute attribute to provide additional information about how the attribute can be used.

Functionality and Capabilities of Attributes

Some key points about attributes include:

  • You can apply one or more attributes to entire assemblies, modules, or smaller program elements such as classes and properties.

  • Attributes can accept arguments in the same way as methods and properties.

  • The process of retrieving metadata from attributes is called reflection. Reflection involves using tools that allow objects to retrieve and examine metadata about their own members. For more information, see Reflection Sample.

See Also

Tasks

How to: Define Your Own Attributes

Reference

AttributeUsageAttribute
System.Attribute

Concepts

Common Uses for Attributes
Application of Attributes
Global Attributes in Visual Basic
Attributes Used in Visual Basic
Attributes and Design-Time Support

Other Resources

Custom Attributes in Visual Basic