|
The CLR's metadata facility is extensible via custom attributes. Custom attributes provide a simple and easy means for developers to annotate a type or its members. A custom attribute is essentially a class; an instance of an attribute class is attached to a type or its members and persisted in the metadata for that type. Custom attributes share some similarities with the IDL extensions described previously:
- As with structured comments, the addition of an attribute does not make the type unusable from a compiler that does not understand the attribute. In general, compilers that do not understand the custom attribute will ignore it. Naturally, this characteristic is both an advantage and a disadvantage; if the compiler does not understand the attribute, then the semantic information it conveys may be lost.
- Because attributes are classes, it is possible to access instances of these classes at runtime to retrieve information. This ability is similar to that offered by IDL extensions that use interfaces to generate information that can be retrieved at runtime. One limitation of custom attributes is the fact that they do not generate code that is automatically called by the CLR at runtime.
Standard Attributes
Some of the attributes are already defined in the .Net framework BCL base class libraries. These attributes are known as standard attributes. There are following standard attributes exist in .Net environment:-
- Obsolete:- This attribute is used to provide the information to the developer that this method is deprecated.
- Webmethod:- This attribute is used by web services to indicate that this method belongs to web services.
The below picture describes the object creation and property hierarchy
 |