1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| foreach (FileInfo fi in list)
{
// for all DLL-files
if (fi.Extension.ToLower().Equals(".dll"))
{
assembly = Assembly.LoadFile(fi.FullName);
Type[] types = assembly.GetTypes();
foreach (Type typ in types)
{
// for all classes, which implements interface IPlugin
if (typ.IsClass && typ.GetInterface("API.Plugin.IPlugin") != null)
{
try
{
obj = Activator.CreateInstance(typ);
mi = typ.GetMethod("Init");
mi.Invoke(obj, null);
mi = typ.GetMethod("DisplayName");
menuName = (string)mi.Invoke(obj, null);
pluginList.Add(new PluginInfo(menuName, typ));
MenuButtonItem mb = new MenuButtonItem(menuName, new System.EventHandler(generalPlugin_Activate));
menuBarItemP.Items.Add(mb);
((IDisposable)obj).Dispose();
}
catch
{
}
}
}
}
} |