当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > use Assembly to call a method

ASP.NET
合理的网盟广告策略:如何规划与投放网盟广告
GoDaddy Backorder域名抢注经验分享
Google Analytics获得GOOGLE真正的收录网站数据指标
Visual Studio 2008 Team Suite简体中文正式版- 激活方法

ASP.NET 中的 use Assembly to call a method


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 54 ::
收藏到网摘: n/a


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; }