Reflection API

Reflection represents an extremely powerful mechanism for working with .NET components. Through the use of reflection, .NET components can be dynamically loaded and their contents discovered at runtime. Metadata is the heart of this functionality and, as such, Metadata can be thought of as a TypeLib on steroids.

The .NET CLR provides for strong runtime type information and provides a System.Type class. After a .NET component is loaded, it is then possible to obtain the type or types contained within the given assembly. To demonstrate the power of Metadata and the Reflection API, create a text file named employee.cs and copy Listing 1.3.4 into it. To compile the listing, issue the following command:

 csc /t:library employee.cs  ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.