December 2001
Intermediate to advanced
416 pages
8h 16m
English
Now that we've decorated our classes with custom attributes, we'll want to access them during the execution of our program. There are several ways to do that. For example, we can invoke the static GetCustomAttributes() method of the Attribute class, passing it a Type object:
static public void retrieveClass1( object obj )
{
Type tp = obj.GetType();
Attribute [] attrs =
Attribute.GetCustomAttributes( tp );
An Attribute array holding an instance of each custom attribute retrieved is returned. If no custom attributes are present, an empty array is returned. Note that intrinsic attributes are not retrieved. For example, the intrinsic Serializable attribute of our class is not returned.
The instance ...
Read now
Unlock full access