共用方式為


Common Uses for Attributes 

In using the common language runtime and class libraries, you probably will need to use attributes at some point. The following list includes a few of the common uses of attributes in code:

  • Marking methods using the WebMethod attribute in XML Web services to indicate that the method should be callable over the SOAP protocol. For more information, see WebMethodAttribute.

  • Describing how to marshal method parameters when interoperating with native code. For more information, see MarshalAsAttribute.

  • Describing the COM properties for classes, methods, and interfaces.

  • Marking components as COM so the Visual Basic compiler will generate the additional code required to create a COM component. For more information, see ComClassAttribute.

  • Calling unmanaged code using the DllImportAttribute class.

  • Describing your assembly in terms of title, version, description, or trademark.

  • Describing which members of a class to serialize for persistence.

  • Describing how to map between class members and XML nodes for XML serialization.

  • Describing the security requirements for methods.

  • Specifying characteristics used to enforce security.

  • Controlling optimizations by the just-in-time (JIT) compiler so the code remains easy to debug.

You can use attributes in many additional ways, and you can also create custom attributes.

See Also

Tasks

How to: Define Your Own Attributes

Concepts

Attributes and Design-Time Support
Attributes Overview in Visual Basic
Application of Attributes
Global Attributes in Visual Basic
Attributes Used in Visual Basic

Other Resources

Custom Attributes in Visual Basic