
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Determining and Obtaining Nested Types Within an Assembly
|
765
{
if (type.IsInterface &&
(type.Name.Equals(interfaceName) ||
interfaceName.Equals("*")))
{
MemberInfo[] members = type.GetMember(memberName, MemberTypes.All,
BindingFlags.Instance | BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Static |
BindingFlags.IgnoreCase);
if (members.Length > 0)
{
foreach(MemberInfo iface in members)
{
Console.WriteLine("Found member {0}.{1}",
type.ToString( ),iface.ToString( ));
}
}
}
}
}
Discussion
The FindIFaceMemberInAssembly method operates very similarly to the FindMemberInAssembly
method of Recipe 13.4. The main difference between this recipe and the one in Rec-
ipe 13.4 is that this method uses the
IsInterface property of the System.Type class to
determine whether this type is an interface. If this property returns
true, the type is
an interface; otherwise, it is a noninterface type.
This recipe also makes use of the
GetMember method of the System.Type class. This
name may contain an
* wildcard character at the end of the string only. If the * wild-
card character is the only character in the name parameter, all members are returned.
If you’d like to do a case-sensitive search, you can omit the
BindingFlags.IgnoreCase
flag from the call to Type.GetMember.
See Also
See Recipes 13.4 ...