if(type.GetInterface("ImyInfo")!=null)
{
ImyInfo o=(ImyInfo)Activator.CreateInstance(type);
MessageBox.Show(o.getMyValue());
}Activator.CreateInstance(type); 返回一个什么?给我你Activator.CreateInstance();代码

解决方案 »

  1.   

    Activator.CreateInstance(type); 返回
    {"plug.myPlug"}
      

  2.   

    源码在就这么点myInfo.cs
    using System;namespace plug
    {
    /// <summary>
    /// myInfo 的摘要说明。
    /// </summary>
    public interface ImyInfo
    {
    string getMyValue();
    }
    }plug.cs
    using System;namespace plug
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    public class myPlug:ImyInfo
    {
    public myPlug()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
    public string getMyValue()
    {
    return "This is a testing interface!!";
    }
    }
    }testplug.cs
    using System;
    using System.Reflection;
    using System.Windows.Forms;
    using plug;namespace test
    {
    /// <summary>
    /// testPlug 的摘要说明。
    /// </summary>
    public class testPlug
    {
    public testPlug()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
    public ImyInfo i=null;
    public void test()
    {
    MessageBox.Show(i.getMyValue());
    }
    public void LoadPlugs()
    { try
    {
    Assembly a = Assembly.LoadFrom("..\\..\\..\\plug\\bin\\debug\\plug.dll");
    System.Type[] types = a.GetTypes();
    foreach(System.Type type in types)
    {
    string str=type.Name;
    if(type.GetInterface("ImyInfo")!=null)
    {
    Object o=Activator.CreateInstance(type);
    MessageBox.Show(((myPlug)o).getMyValue());
    }
    }
    }
    catch(Exception e)
    {
    //MessageBox.Show(e.Message);
    string str=e.Message;
    }
    } }
    }