
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
516
|
Chapter 9: Delegates, Events, and Anonymous Methods
FlattenHierarchy
Include all static members in the inheritance hierarchy in the search (do not
include static members of nested types in the search).
IgnoreCase
Perform a case-insensitive search.
Instance
Include instance members in the search.
NonPublic
Include nonpublic members in the search.
Public
Include public members in the search.
Static
Include static members in the search.
You need to create more flexible and advanced searches for members that do not
involve creating your own member search engine, such as a code generation tool that
uses preexisting assemblies as an input might need.
Solution
The FindMembers method of a Type object can be used, along with a callback, to cre-
ate your own complex searches. The
TestSearchMembers method shown in Example 9-9
will call your custom member-searching method,
SearchMembers.
Example 9-9. Performing advanced member searches on a type
using System;
using System.Reflection;
public class SearchType
{
public void TestSearchMembers( )
{
MemberInfo[] members = SearchMembersByReturnType(this.GetType( ),
Type.GetType("System.Int32"));
if (members.Length > 0)
{
Console.WriteLine("Matches found:");
// Display information for each match.
for(int counter = 0; counter < members.Length; counter++)
{
Console.WriteLine("\tMember ...