Information Technology Reference
In-Depth Information
The Stages of an Attribute
There are three stages in the process of using an attribute—declaring the attribute, applying
the attribute, and consuming the attribute. These stages are illustrated in Figure 21-2.
1.
Before an attribute can be used, it must be declared.
-
Predefined attributes are declared in the .NET Framework.
-
Custom attributes are user-defined attributes.
2.
The next step is applying an attribute to the target construct. You do this by placing the
attribute in the source code above the target construct.
3.
The last step is consuming , or using, an attribute. This is done from a running program,
which accesses the metadata stored by the attribute.
Figure 21-2. The stages of an attribute
In the preview program you just looked at, the three phases of using the Obsolete attribute
are the following:
Declare the attribute : The Obsolete attribute is predefined in the .NET Framework, so
this step was unnecessary.
￿
Apply the attribute : The attribute was applied to method PrintOut , in the square braces
construct, immediately before the declaration of the method.
￿
￿
Use the attribute : In this case, the compiler was the consumer that used the attribute and
took the action of producing the warning message.
Search WWH ::




Custom Search