Chapter 12. Reflection and Attributes


C# programs are self-describing . When you compile a C# program, part of the EXE or DLL you generate contains metadata (extra information) that tells you the classes that your EXE or DLL contains. It also tells you about the members of each class: the fields, properties, methods , delegates, events, etc. This information is always available to your program and other programs, and can be reached through a mechanism known as reflection. In addition to being able to read information about a particular class and its members, it's also possible to extend this metadata with attributes. Attributes are classes that extend the metadata about a certain class or member in the class. You can create your own attributes easily, as you will see shortly.

Attributes are inert classes, in the sense that they don't consume memory unless a program looks for them. If a program specifically looks for a certain attribute, the runtime will then activate the attribute. It does this by creating an instance of the attribute class and calling one of its constructors.



C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net