
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
756
|
Chapter 13: Reflection
AssemblyName type is made up of members that allow access to the information about
an assembly, such as the name, version, culture information, public/private key
pairs, and other data.
Note that this method does not account for assemblies loaded using the
Assembly.
ReflectionOnlyLoad*
methods, as it is inspecting for only compile-time references.
When loading assemblies for inspection using reflection, you should
use the
ReflectionOnlyLoad* methods. These methods do not allow
you to execute code from the loaded assembly.
See Also
See the “Assembly Class” topic in the MSDN documentation.
13.2 Listing Exported Types
Problem
You need to obtain all the exported types of an assembly. This information allows
you to see what types are usable from outside of this assembly.
Solution
Use Assembly.GetExportedTypes to obtain the exported types of an assembly:
using System;
using System.Reflection;
public static void ListExportedTypes(string path)
{
// Load the assembly.
Assembly asm = Assembly. ReflectionOnlyLoadFrom(path);
Console.WriteLine("Assembly: {0} imports:",path);
// Get the exported types.
Type[] types = asm.GetExportedTypes( );
foreach (Type t in types)
{
Console.WriteLine ("\tExported Type: {0}",t.FullName);
}
}
The previous example will display all exported, or public, ...