繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> 评论及其它 >> use Assembly to call a method

use Assembly to call a method

2005-08-29 00:10:57  作者:crabo  来源:互联网  浏览次数:2  文字大小:【】【】【
简介:When using objectFactory,u may want to call a static method,but would not like to write a mass of interfaces to *Show* the method.Here,it's a way.Code:using System.Reflection;try   ...
关键字:Assembly method call use to

When using objectFactory,u may want to call a static method,but would not like to write a mass of interfaces to *Show* the method.Here,it's a way.

Code:

using System.Reflection;

try

{

Assembly asm =Assembly.Load("FC.Shared.Common");

Type t = asm.GetType("FC.Shared.Common.CMessage");

MethodInfo minfo=t.GetMethod("Send");

Object obj = Activator.CreateInstance(t);

//Object obj=asm.CreateInstance("FC.Shared.Common.CMessage");

minfo.Invoke(obj,new string []{"IMMsgOut","Sender","Recipient","hello","Body","BizBody"});

}

catch(Exception e)

{

MessageBox.Show(e.InnerException.Message);

throw e.InnerException;

}

责任编辑:admin
相关文章