c#动态加载dll中的类
public class SchemaAssmbly
{
private string assmblyFile = "";
private string objectType = "";
public object realObject = null;
public SchemaAssmbly(string assmblyFile, string objectType)
{
this.assmblyFile = assmblyFile;
this.objectType = objectType;
}
public bool CreateRealObject()
{
if (realObject == null)
{
try
{
if (System.IO.File.Exists(this.assmblyFile))
{
System.Reflection.Assembly assmbly = System.Reflection.Assembly.LoadFile(assmblyFile);
if (assmbly != null)
{
object theObject = assmbly.CreateInstance(objectType, true);
if (theObject != null)
{
realObject = theObject;
return true;
}
}
}
return false;
}
catch (Exception)
{
return false;
}
}
return true;
}
}
{
private string assmblyFile = "";
private string objectType = "";
public object realObject = null;
public SchemaAssmbly(string assmblyFile, string objectType)
{
this.assmblyFile = assmblyFile;
this.objectType = objectType;
}
public bool CreateRealObject()
{
if (realObject == null)
{
try
{
if (System.IO.File.Exists(this.assmblyFile))
{
System.Reflection.Assembly assmbly = System.Reflection.Assembly.LoadFile(assmblyFile);
if (assmbly != null)
{
object theObject = assmbly.CreateInstance(objectType, true);
if (theObject != null)
{
realObject = theObject;
return true;
}
}
}
return false;
}
catch (Exception)
{
return false;
}
}
return true;
}
}