.NET Attributes and Reflection
One of the most fascinating things about .NET is the notion attributes that can be applied to pieces of code. An attribute is basically a way of associating some extra information to a class, a method or a property.This is in itself quite useful, but where this really becomes interesting is that these attributes can be queried at runtime. What's even more interesting is that you as the programmer, can create your own attributes (attributes are really just a class that extends the System.Attribute class). See the class declaration for the custom attribute below:
<AttributeUsage(AttributeTargets.Class, _
Inherited:=True, _
AllowMultiple:=True)> _
Public Class ClassModifiedAttribute : Inherits System.Attribute
This defines a class called "ClassModifiedAttribute". This attribute class has, in itself, attributes
attached to it (see how pervasive attributes are?). The "AttributeTargets" argument declares that this custom
attribute will be used to describle classes. The "AllowMultiple" argument indicates that multiple instances of
this attribute can be attached to a class.
back
|
next
|
about