如何通过反射得到一个接口的基类接口 public interface IBase{ }public interace IChild:Ibase{}通过typof(IChild)时无法得到BaseType.怎么通过反射得到它的基类接口 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Type(IClild).InvokeMember方法怎么不能调用基类的方案。是否非得到基类才可以调用的啊 msdn 的例子,用FindInterfacesusing System;using System.Xml;using System.Reflection;public class MyFindInterfacesSample { public static void Main() { try { XmlDocument myXMLDoc = new XmlDocument(); myXMLDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); Type myType = myXMLDoc.GetType(); // Specify the TypeFilter delegate that compares the // interfaces against filter criteria. TypeFilter myFilter = new TypeFilter(MyInterfaceFilter); String[] myInterfaceList = new String[2] {"System.Collections.IEnumerable", "System.Collections.ICollection"}; for(int index=0; index < myInterfaceList.Length; index++) { Type[] myInterfaces = myType.FindInterfaces(myFilter, myInterfaceList[index]); if (myInterfaces.Length > 0) { Console.WriteLine("\n{0} implements the interface {1}.", myType, myInterfaceList[index]); for(int j =0;j < myInterfaces.Length;j++) Console.WriteLine("Interfaces supported: {0}.", myInterfaces[j].ToString()); } else Console.WriteLine( "\n{0} does not implement the interface {1}.", myType,myInterfaceList[index]); } } catch(ArgumentNullException e) { Console.WriteLine("ArgumentNullException: " + e.Message); } catch(TargetInvocationException e) { Console.WriteLine("TargetInvocationException: " + e.Message); } catch(Exception e) { Console.WriteLine("Exception: " + e.Message); } } public static bool MyInterfaceFilter(Type typeObj,Object criteriaObj) { if(typeObj.ToString() == criteriaObj.ToString()) return true; else return false; }} MessageBox.Show(typeof(IChild).GetInterfaces()[0].ToString());BaseType 是返回类实例的基类,而且类只有一个基类而借口可以有多个父接口,所以只能查询 写得太快写错了,是BaseType 是返回类的基类, 修改从网上找的程序名称 请教正则问题 序列化一个类为xml时,如何加入encoding属性? 自已有个 form1,怎么让这个form1成为用户控件? c#指针问题,请大家帮忙! dategrid中显示出了数据 我想取得其中的一个单元格的值 怎么做?? string 和 stringbuilder有什么区别,各自在什么情况下使用 请思归,孟子,速马等大侠给解惑一下,帮顶者有分 解码 winform webBrowser控件 自定义右键菜单 存储过程执行dll windwos应用程序如何保存全局变量
using System.Xml;
using System.Reflection;public class MyFindInterfacesSample
{
public static void Main()
{
try
{
XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" + "</book>");
Type myType = myXMLDoc.GetType(); // Specify the TypeFilter delegate that compares the
// interfaces against filter criteria.
TypeFilter myFilter = new TypeFilter(MyInterfaceFilter);
String[] myInterfaceList = new String[2]
{"System.Collections.IEnumerable",
"System.Collections.ICollection"};
for(int index=0; index < myInterfaceList.Length; index++)
{
Type[] myInterfaces = myType.FindInterfaces(myFilter,
myInterfaceList[index]);
if (myInterfaces.Length > 0)
{
Console.WriteLine("\n{0} implements the interface {1}.",
myType, myInterfaceList[index]);
for(int j =0;j < myInterfaces.Length;j++)
Console.WriteLine("Interfaces supported: {0}.",
myInterfaces[j].ToString());
}
else
Console.WriteLine(
"\n{0} does not implement the interface {1}.",
myType,myInterfaceList[index]);
}
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: " + e.Message);
}
catch(TargetInvocationException e)
{
Console.WriteLine("TargetInvocationException: " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
public static bool MyInterfaceFilter(Type typeObj,Object criteriaObj)
{
if(typeObj.ToString() == criteriaObj.ToString())
return true;
else
return false;
}
}
MessageBox.Show(typeof(IChild).GetInterfaces()[0].ToString());
BaseType 是返回类实例的基类,而且类只有一个基类
而借口可以有多个父接口,所以只能查询
BaseType 是返回类的基类,