Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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 Class.
  • Describing how to marshal method parameters when interoperating with native code. For more information, see MarshalAsAttribute Class.
  • 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 Class.
  • 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

Attributes and Design-Time Support | WebMethodAttribute Class | MarshalAsAttribute Class | COMClassAttribute Class | DllImportAttribute Class | Attributes Overview | Application of Attributes | Global Attributes | Custom Attributes | Defining Your Own Attributes | Attributes used in Visual Basic .NET

Show:
© 2015 Microsoft