/// <summary> /// Returns a new plugin and the assembly location. /// </summary> /// <param name="file"></param> /// <returns></returns> public static PluginInfo AddPlugin(string file) { Assembly assembly = Assembly.LoadFile(file); //PluginVersionAttribute version = (PluginVersionAttribute)Attribute.GetCustomAttribute(assembly, // typeof(PluginVersionAttribute)); //if (version != null && version.VersonNumber == "1.0.0") //{ MainContentAttribute contentAttribute = (MainContentAttribute)Attribute.GetCustomAttribute(assembly, typeof(MainContentAttribute)); IPlugin plugin = (IPlugin)assembly.CreateInstance(contentAttribute.Content, true); PluginInfo pluginInfo = new PluginInfo(); pluginInfo.AssemblyPath = file; pluginInfo.Plugin = plugin; return(pluginInfo); //} //else //{ // return null; // //txtDescription.Text = "You tried to load an unsupported assembly"; //} }
/// <summary> /// Creates a new instance of the plugin inside the specified assembly file /// </summary> /// <typeparam name="T">Form / UserControl</typeparam> /// <param name="assemblyFile">The assembly file to load</param> /// <returns></returns> public static T CreateNewInstance <T>(string assemblyFile) { Assembly assembly = Assembly.LoadFile(assemblyFile); MainContentAttribute contentAttribute = (MainContentAttribute)Attribute.GetCustomAttribute(assembly, typeof(MainContentAttribute)); T item = (T)assembly.CreateInstance(contentAttribute.Content, true); return(item); }