For the attributes in the metadata to be useful, you need a
way to access them at runtime. The classes in the
Reflection namespace, along with the
System.Type class, provide support for examining
and interacting with the metadata.
Reflection is generally used for any of four tasks:
This might be used by tools and utilities that wish to display metadata, or by class library features that modify their behavior based on metadata.
Your code can examine the types in an assembly and interact with or instantiate those types. An application that supports plug-ins might use this to discover what features a plug-in DLL offers.
This allows the programmer to invoke properties and methods on objects dynamically instantiated, based on type discovery. This is also known as dynamic invocation. (As we’ll see in Chapter 18, C# 4.0 has introduced an easier way to do this than using reflection.)
You can generate new types at runtime. You might do this when a custom class containing code generated at runtime, specialized for a particular task, will run significantly faster than a more general-purpose solution. This is an advanced technique that is beyond the scope of this book.
In this section, we will use the C# reflection support to read the
metadata in the
The reflection system defines numerous classes, each designed to provide information about a particular ...