首页 > 学院 > 开发设计 > 正文

use Assembly to call a method

2019-11-17 05:25:29
字体:
来源:转载
供稿:网友
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;
   }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表