怎样动态执行 某未知 类中的函数?

mty 2004-04-15 01:33:31
string strType = "Int";
string strCallMe = "Test.CallMe";
string strPara1 = "String strVal";

int nRet = (int)ExcuteFunction(strCallMe, strPara1);
C#中有这样的功能吗?
...全文
47 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2004-04-22
  • 打赏
  • 举报
回复
System.Reflection.Assembly mAssembly=System.Reflection.Assembly.LoadFrom(FileName);

Type tmpType= mAssembly.GetType(mAssembly.GetName().Name+".ClassName");

System.Reflection.MethodInfo myMethodInfo=tmpType.GetMethod("MethodName");
if (myMethodInfo==null)
{
MessageBox.Show("不存的方法!"); //在相应的类型中没有找到相应的方法。
return false;
}

try
{
object[] objParas=new object[1];
myMethodInfo.Invoke(tmpObject,new object[]{SomeValues});
return true;
}
catch (Exception ex)
{
return false;
}

不太完整,但可参考一下,MSDN上也有的.
mty 2004-04-22
  • 打赏
  • 举报
回复
没人知道吗?
mty 2004-04-16
  • 打赏
  • 举报
回复
能详细说说?
javavbling 2004-04-15
  • 打赏
  • 举报
回复
用反射机制

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧