C# TypeInfo FindMembers
Description
TypeInfo FindMembers
Returns a filtered array of MemberInfo
objects of the specified member type.
Syntax
TypeInfo.FindMembers
has the following syntax.
public virtual MemberInfo[] FindMembers(
MemberTypes memberType,/*w w w .ja v a2 s . c o m*/
BindingFlags bindingAttr,
MemberFilter filter,
Object filterCriteria
)
Parameters
TypeInfo.FindMembers
has the following parameters.
memberType
- An object that indicates the type of member to search for.bindingAttr
- A bitmask comprised of one or more BindingFlags that specify how the search is conducted.bindingAttr
- -or-bindingAttr
- Zero, to return null.filter
- The delegate that does the comparisons, returning true if the member currently being inspected matches the filterCriteria and false otherwise. You can use the FilterAttribute, FilterName, and FilterNameIgnoreCase delegates supplied by this class. The first uses the fields of FieldAttributes, MethodAttributes, and MethodImplAttributes as search criteria, and the other two delegates use String objects as the search criteria.filterCriteria
- The search criteria that determines whether a member is returned in the array of MemberInfo objects.filterCriteria
- The fields of FieldAttributes, MethodAttributes, and MethodImplAttributes can be used in conjunction with the FilterAttribute delegate supplied by this class.
Returns
TypeInfo.FindMembers
method returns
Example
using System;// ww w . ja v a 2s. c o m
using System.Reflection;
class MyFindMembersClass
{
public static void Main()
{
Object objTest = new Object();
Type objType = objTest.GetType ();
MemberInfo[] arrayMemberInfo;
arrayMemberInfo = objType.FindMembers(MemberTypes.Method,
BindingFlags.Public,
new MemberFilter(DelegateToSearchCriteria),"ReferenceEquals");
for(int index=0;index < arrayMemberInfo.Length ;index++)
Console.WriteLine (arrayMemberInfo[index].ToString());
}
public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, Object objSearch)
{
if(objMemberInfo.Name.ToString() == objSearch.ToString())
return true;
else
return false;
}
}