看一下这个例子using System;
using System.Reflection;class MyFindMembersClass
{
public static void Main()
{
Object objTest = new Object();
Type objType = objTest.GetType ();
MemberInfo[] arrayMemberInfo;
try
{
//Find all static or public methods in the Object class that match the specified name.
arrayMemberInfo = objType.FindMembers(MemberTypes.Method,
BindingFlags.Public | BindingFlags.Static| BindingFlags.Instance,
new MemberFilter(DelegateToSearchCriteria),
"ReferenceEquals"); for(int index=0;index < arrayMemberInfo.Length ;index++)
Console.WriteLine ("Result of FindMembers -\t"+ arrayMemberInfo[index].ToString() +"\n");
}
catch (Exception e)
{
Console.WriteLine ("Exception : " + e.ToString() );
}
}
public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, Object objSearch)
{
// Compare the name of the member function with the filter criteria.
if(objMemberInfo.Name.ToString() == objSearch.ToString())
return true;
else
return false;
}
}
using System.Reflection;class MyFindMembersClass
{
public static void Main()
{
Object objTest = new Object();
Type objType = objTest.GetType ();
MemberInfo[] arrayMemberInfo;
try
{
//Find all static or public methods in the Object class that match the specified name.
arrayMemberInfo = objType.FindMembers(MemberTypes.Method,
BindingFlags.Public | BindingFlags.Static| BindingFlags.Instance,
new MemberFilter(DelegateToSearchCriteria),
"ReferenceEquals"); for(int index=0;index < arrayMemberInfo.Length ;index++)
Console.WriteLine ("Result of FindMembers -\t"+ arrayMemberInfo[index].ToString() +"\n");
}
catch (Exception e)
{
Console.WriteLine ("Exception : " + e.ToString() );
}
}
public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, Object objSearch)
{
// Compare the name of the member function with the filter criteria.
if(objMemberInfo.Name.ToString() == objSearch.ToString())
return true;
else
return false;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货