if (this.openFileDialog.ShowDialog() == DialogResult.OK)
            {
                namestr = null;
                namestr = openFileDialog.FileNames;
                treeView1.Nodes.Clear();
                for (int i = 0; i < namestr.Length; i++)
                {
                    string[] tem = namestr[i].Split('\\');
                    this.treeView1.Nodes.Add(tem[tem.Length - 1]);
                    treeView1.Nodes[i].ImageIndex = 1;
                    System.Reflection.Assembly getDll = System.Reflection.Assembly.LoadFrom(namestr[i]);
                    typ= getDll.GetTypes();                   
                    for (int k = 0; k < typ.Length; k++)
                    {
                        string[] temname = typ[k].ToString().Split('.');
                 treeView1.Nodes[i].Nodes.Addtemnametemname.Length - 1]);
                    }
                 }
            }已经获得DLL中的类 怎么获得接口?如果有的话。

解决方案 »

  1.   

    接口是对一个类型来说的,比如:Type type=Type.GetType(name);
    type.GetInterfaces();
      

  2.   

    下面的示例获取指定类的类型,并显示该类型实现或继承的所有接口using System;
    using System.Web;
    using System.Web.UI;namespace Samples
    {
        public class MyTemplate : Control, INamingContainer 
        {
            private String _message = null;
            public String Message 
            {
                get 
                {
                    return _message;
                }
                set 
                {
                    _message = value;
                }
            }
        }
        public class MyInterfacesSample
        {
            public static void Main()
            {
                try
                {
                    Type[] myObjectArray= typeof(MyTemplate).GetInterfaces();
                    Console.WriteLine("The interfaces inherited by the MyTemplate class are:\n");
                    for (int index = 0; index < myObjectArray.Length; index++)
                    {
                        Console.WriteLine(myObjectArray[index]);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("An exception occurred.");
                    Console.WriteLine("Message: " + e.Message);
                }
            }
        }
    }
      

  3.   

    谢谢 结帖
    对了,还有个小问题
    我在获取DLL时 好象要DLL文件在当前工作目录下?
      

  4.   

    使用Application.StartPath来相对计算就可以了。