龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

use Assembly to call a method

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
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 =

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;

   }

  

精彩图集

赞助商链接