C#
Querying Metadata with ReflectionC# - Querying Metadata with Reflection
The Reflection API Hierarchy
The Type Class
Retrieving the Type of an Instance
Retrieving the Type from a Name
Interrogating Types
Working with Assemblies and Modules
Iterating Through the Types of an Assembly
Listing an Assembly's Modules
Late Binding with Reflection
Creating and Executing Code at Run Time
Summary
In tutorial 2, "Introducing Microsoft .NET," I touched on the fact that the compiler generates a Win32-portable executable (PE) comprising mainly MSIL and metadata. One very powerful feature of .NET is that it allows you to write code to access an application's metadata through a process known as reflection. Put simply, reflection is the ability to discover type information at run time. This tutorial will describe the reflection API and how you can use it to iterate through an assembly's modules and types and to retrieve the different design-time characteristics of a type. You'll also see several advanced usages of reflection, such as dynamically invoking methods and use type information (through late binding) and even creating and executing MSIL code at run time!