110,534
社区成员
发帖
与我相关
我的任务
分享
try
{
//動態加載dll文件,
string sDllName = ServiceId.Substring(0,ServiceId.IndexOf("."));
Assembly DllAssembly = Assembly.Load(sDllName);
//執行選定的類別
ISDServer.ITransaction Tx = (ISDServer.ITransaction)DllAssembly.CreateInstance(sDllName+".Transaction");
return Tx.Execute((ISDServer.IProcess)this,ServiceId,oType,sParam);
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;
}
}
}