예제 #1
0
파일: Form1.cs 프로젝트: Maziilla/Com_n4
        public Dictionary <string, IPlugin> FindPlugins()
        {
            Dictionary <string, IPlugin> plugins = new Dictionary <string, IPlugin>();
            // папка с плагинами
            string folder = System.AppDomain.CurrentDomain.BaseDirectory;

            // dll-файлы в этой папке
            string[] files = Directory.GetFiles(folder, "*.dll");

            foreach (string file in files)
            {
                try
                {
                    Assembly assembly = Assembly.LoadFile(file);

                    foreach (Type type in assembly.GetTypes())
                    {
                        Type iface = type.GetInterface("Interface.IPlugin");

                        if (iface != null)
                        {
                            Interface.IPlugin plugin = (Interface.IPlugin)Activator.CreateInstance(type);
                            plugins.Add(plugin.Name, plugin);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка загрузки плагина\n" + ex.Message);
                }
            }
            return(plugins);
        }
예제 #2
0
파일: Form1.cs 프로젝트: Maziilla/Com_n4
 private void OnPluginClick(object sender, EventArgs args)
 {
     Interface.IPlugin plugin = (Interface.IPlugin)plugins[((ToolStripMenuItem)sender).Text];
     plugin.Transform(this);
 }