

























Type T = typeof(KQV1.DataAccess.ConnectionBuilder);
string s = T.Assembly.FullName.ToString();
Assembly SampleAssembly = Assembly.Load(s);
MessageBox.Show(s);
private Form LoadFromAsmbl(string strAsmblPath, string strClassName)
{
// 验证你的程序集是不是存在,你的总不能去引用一个不存在的东西吧?
if(!File.Exists(strAsmblPath))
{
MessageBox.Show("Assembly Not Exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}

// 这里就加载程序集了,有很多种方式。去MSDN上看看吧
Assembly asmbl = null;
try
{
asmbl = Assembly.LoadFrom(strAsmblPath);
if (asmbl == null)
{
throw new Exception("Fail to load assembly " + strAsmblPath);
}
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}

// 实例化你要的对象,如果成功的话就没问题了*_*
Form frmController = null;
try
{
frmController = (Form)asmbl.CreateInstance(strClassName);
if (frmController == null)
{
throw new Exception("Fail to create instance of " + strClassName);
}
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}

// 到这里你就可以放心了*_*
return frmController;
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。