
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
764
|
Chapter 13: Reflection
See Also
See Recipe 13.10; see the “Assembly Class,” “BindingFlags Enumeration,” and
“MemberInfo Class” topics in the MSDN documentation.
13.5 Finding Members Within an Interface
Problem
You need to find one or more members with a specific name, or a part of a name,
that belong to an interface.
Solution
Use the same technique outlined in Recipe 13.4, but filter out all types except inter-
faces. The first overloaded version of the
FindIFaceMemberInAssembly method finds a
member specified by the
memberName parameter in all interfaces contained in an
assembly. Its source code is:
public static void FindIFaceMemberInAssembly(string asmPath, string memberName)
{
// Delegates to the overloaded FindIFaceMemberInAssembly method
// passing in a wildcard character as the interfaceName param.
FindIFaceMemberInAssembly(asmPath, memberName, "*");
}
The second overloaded version of the FindIFaceMemberInAssembly method finds a
member in the interface specified by the
interfaceName parameter. Its source code is:
public static void FindIFaceMemberInAssembly(string asmPath, string memberName,
string interfaceName)
{
Assembly asm = Assembly.LoadFrom(asmPath);
foreach(Type type in asm.GetTypes( ))
Table 13-1. MemberTypes enumeration values
Enumeration value Definition
All All member types ...