通过C#的Assembly反射机制可以动态的调用一个类以及该类中的方法和属性:
string spath = this.TargetPath.Trim().Trim('\\')+"\\DB.dll";
Assembly a = Assembly.LoadFrom(spath); //获得dll路径
Type calltype = a.GetType("SystemAdmin.DbBase");
object Callobject = Activator.CreateInstance(calltype); //Activator.CreateInstance创建实例
string method = "sGetSubSystemID";
object returnvalue = 0;
Type t = Callobject.GetType();
MethodInfo [] m = t.GetMethods() ;
object result;
for(int i = 0; i < m.Length; i++)
{
if(m[i].Name == method)
{
result = m[i].Invoke(Callobject,null);
}
}
string spath = this.TargetPath.Trim().Trim('\\')+"\\DB.dll";
Assembly a = Assembly.LoadFrom(spath); //获得dll路径
Type calltype = a.GetType("SystemAdmin.DbBase");
object Callobject = Activator.CreateInstance(calltype); //Activator.CreateInstance创建实例
string method = "sGetSubSystemID";
object returnvalue = 0;
Type t = Callobject.GetType();
MethodInfo [] m = t.GetMethods() ;
object result;
for(int i = 0; i < m.Length; i++)
{
if(m[i].Name == method)
{
result = m[i].Invoke(Callobject,null);
}
}