
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
518
|
Chapter 9: Delegates, Events, and Anonymous Methods
FindMembers method of the searchType object passed to it. Notice that the returnType
parameter is passed to the FindMembers method as the last parameter.
The
MemberFilter delegate, filterCallback, defines the ReturnTypeFilter method
to be called for each member that meets the specified criteria of the
FindMembers
method (i.e., MemberTypes.All, BindingFlags.Instance, BindingFlags.Public, Binding-
Flags.NonPublic
, and BindingFlags.Static). The real power of this search mechanism
lies in the
ReturnTypeFilter callback method.
This callback method casts the member parameter to the correct member type (i.e.,
MethodInfo or PropertyInfo), obtains the return type, and compares that return type
to the one passed in to the
returnType parameter of the SearchMembersByReturnType
method. A return value of true indicates that the return types matched; a false indi-
cates they did not match.
Discussion
Most complex member searches can be made easier through the use of the
FindMembers method of a Type object. This method returns an array of MemberInfo
objects that contain all members that match the memberType, bindingAttr, and
filterCriteria parameters.
This method makes use of the
MemberFilter delegate, which is passed in to the
filter parameter. This