WEB开发网
开发学院软件开发C++ use Assembly to call a method 阅读

use Assembly to call a method

 2008-03-08 12:55:55 来源:WEB开发网   
核心提示: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
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;
  }

Tags:use Assembly to

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接