动态加载dll

string   DllPath   =   Application.StartupPath   +   @ "\someDLL.dll "; 
System.Reflection.Assembly   assmble   =   System.Reflection.Assembly.LoadFile(DllPath); 
Type   tmpType   =   assmble.GetType( "someDLL.ClassA "); 
System.Reflection.MethodInfo   tmpM   =   tmpType.GetMethod( "Add "); 
object   tmpobj   =   assmble.CreateInstance( "someDLL.ClassA "); 
int   i   =   (int)tmpM.Invoke(tmpobj,   new   object[]{2,3}); 
----------ClassA的定义-------------------- 
using   System; 
namespace   someDLL 
///   <summary> 
///   ClassA   的摘要说明。 
///   </summary> 
public   class   ClassA 
public   ClassA() 
// 
//   TODO:   在此处添加构造函数逻辑 
// 
public   int   Add(int   a,   int   b) 
return   a+b; 
posted @ 2011-03-19 15:51  与时俱进  阅读(957)  评论(0编辑  收藏  举报
友情链接:同里老宅院民居客栈