PART I
C h a p t e r 1 7 :
R u n t i m e T y p e I D , R e f l e c t i o n , a n d A t t r i b u t e s
485
PART IPART I
When attaching an attribute, it is not actually necessary to specify the
Attribute
suffix.
For example, the preceding class could be declared this way:
[Remark("This class uses an attribute.")]
class UseAttrib {
// ...
}
Here, only the name
Remark
is used. Although the short form is correct, it is usually safer
to use the full name when attaching attributes, because it avoids possible confusion and
ambiguity.
Obtaining an Object’s Attributes
Once an attribute has been attached to an item, other parts of the program can retrieve the
attribute. To retrieve an attribute, you will usually use one of two methods. The first is
Do'stlaringiz bilan baham: |