映射时,总是出现转换失败是怎么回事? if(type.GetInterface("ImyInfo")!=null) { ImyInfo o=(ImyInfo)Activator.CreateInstance(type); MessageBox.Show(o.getMyValue()); }Activator.CreateInstance(type); 返回一个什么?给我你Activator.CreateInstance();代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Activator.CreateInstance(type); 返回{"plug.myPlug"} 源码在就这么点myInfo.csusing System;namespace plug{ /// <summary> /// myInfo 的摘要说明。 /// </summary> public interface ImyInfo { string getMyValue(); }}plug.csusing System;namespace plug{ /// <summary> /// Class1 的摘要说明。 /// </summary> public class myPlug:ImyInfo { public myPlug() { // // TODO: 在此处添加构造函数逻辑 // } public string getMyValue() { return "This is a testing interface!!"; } }}testplug.csusing 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; } } }} 求助insert into values提示我对象名“用户”无效,或者values附近有语法错误 vs2008数据库打开后是二进制数 LINQ TO XML 获取根节点属性 在线等 C#.net串口通讯 C#调用COM的问题 textbox接收输入内容?急!!! 怎样得到数据库修改前和修改后的字段值? 想做个用户控件不知如何下手???请教。。。 .net如何用PL/SQL与连接Oracle连接?连接字符串出现问题了............... 请问DataGrid从表的风格怎么设置? 如何在C#中执行JS文件,输出执行结果 水晶报表问题,急!
{"plug.myPlug"}
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;
}
} }
}