Discovering and Examining Types

Reflection lets you examine an assembly and discover what types the assembly defines. You can also get more information about a type at runtime by examining that type in some detail. We'll take a look at how to discover a type first.

Discovering Types

You can discover defined types by loading an assembly with the Assembly.Load method, which creates an Assembly object, and using the GetTypes method of that object, which returns an array of Type objects:

public static void Main()
{
  Assembly assembly = Assembly.Load("ch14_03");
  Type[] types = assembly.GetTypes();
    .
    .
    .

After you have an array of Type objects, you can loop over each type and display it using a foreach loop, as you see in ch14_04.cs, Listing 14.4 ...

Get Microsoft® Visual C#® .NET 2003 Kick Start 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.