public interface IBase
{
   
}public interace IChild:Ibase
{}通过typof(IChild)时无法得到BaseType.怎么通过反射得到它的基类接口

解决方案 »

  1.   

    在Type(IClild).InvokeMember方法怎么不能调用基类的方案。是否非得到基类才可以调用的啊
      

  2.   

    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;
        }
    }
      

  3.   


               MessageBox.Show(typeof(IChild).GetInterfaces()[0].ToString());
    BaseType 是返回类实例的基类,而且类只有一个基类
    而借口可以有多个父接口,所以只能查询
      

  4.   

    写得太快写错了,是
    BaseType 是返回类的基类,