Extend metadata using attributes
The common language runtime allows you to add keyword-like descriptive declarations, called attributes, to annotate programming elements such as types, fields, methods, and properties. When you compile your code for the runtime, it is converted into common intermediate language (CIL) and placed inside a portable executable (PE) file along with metadata generated by the compiler. Attributes allow you to place extra descriptive information into metadata that can be extracted using runtime reflection services. The compiler creates attributes when you declare instances of special classes that derive from System.Attribute.
.NET uses attributes for a variety of reasons and to address a number of issues. Attributes describe how to serialize data, specify characteristics that are used to enforce security, and limit optimizations by the just-in-time (JIT) compiler so the code remains easy to debug. Attributes can also record the name of a file or the author of code, or control the visibility of controls and members during forms development.
Related articles
Title | Description |
---|---|
Applying Attributes | Describes how to apply an attribute to an element of your code. |
Writing Custom Attributes | Describes how to design custom attribute classes. |
Retrieving Information Stored in Attributes | Describes how to retrieve custom attributes for code that is loaded into the execution context. |
Metadata and Self-Describing Components | Provides an overview of metadata and describes how it is implemented in a .NET portable executable (PE) file. |
How to: Load Assemblies into the Reflection-Only Context | Explains how to retrieve custom attribute information in the reflection-only context. |