string file = Application.StartupPath + “AAA.DLL”;
if (file.ToUpper().EndsWith(".DLL"))
{
try
{
//载入dll
Assembly ab = Assembly.LoadFrom(file);
Type[] types = ab.GetTypes();
foreach (Type t in types)
{
if (t.GetInterface("IPugin") != null) 如果某些类实现了预定义的IPugin接口
{
Logger.Add("加载插件成功!" + file);
plugin.Instance = ab.CreateInstance(t.FullName);
}
}
}
catch (Exception ex)
{
_strMessage = "加载插件失败,请检查插件配置!" + ex.Message;
return false;
}
}