public void RegisterImporter <T, U>() where U : ContentImporter <T> { if (Importers.ContainsKey(typeof(U))) { return; // TODO: Throw/log something in future? } Importers.Add(typeof(T), Activator.CreateInstance <U>()); }
public TLCGenPluginManager(string pluginpath) { try { if (Directory.Exists(pluginpath)) { // Find all Generator DLL's foreach (String file in Directory.GetFiles(pluginpath)) { if (Path.GetExtension(file).ToLower() == ".dll") { // Find and loop all types from the assembly var assemblyInstance = Assembly.LoadFrom(file); var types = assemblyInstance.GetTypes(); var bFound = false; foreach (Type t in types) { // Find TLCGenPluginAttribute attribute, and if found, continue var attr = (TLCGenPluginAttribute)Attribute.GetCustomAttribute(t, typeof(TLCGenPluginAttribute)); if (attr != null) { var plugin = Activator.CreateInstance(t); if ((attr.PluginElements & TLCGenPluginElems.Generator) == TLCGenPluginElems.Generator) { Generators.Add(plugin as ITLCGenGenerator); } if ((attr.PluginElements & TLCGenPluginElems.Importer) == TLCGenPluginElems.Importer) { Importers.Add(plugin as ITLCGenImporter); } if ((attr.PluginElements & TLCGenPluginElems.MenuControl) == TLCGenPluginElems.MenuControl) { MenuItems.Add(plugin as ITLCGenMenuItem); } if ((attr.PluginElements & TLCGenPluginElems.TabControl) == TLCGenPluginElems.TabControl) { TabItems.Add(plugin as ITLCGenTabItem); } if ((attr.PluginElements & TLCGenPluginElems.ToolBarControl) == TLCGenPluginElems.ToolBarControl) { TabItems.Add(plugin as ITLCGenTabItem); } bFound = true; } } if (!bFound) { //#if !DEBUG System.Windows.MessageBox.Show($"Library {file} wordt niet herkend als TLCGen addin."); //#endif } } } } else { } } catch { throw new NotImplementedException(); } }