Пример #1
0
        void Load(string path, bool needsInit)
        {
            try {
                Assembly lib   = Assembly.LoadFrom(path);
                Type[]   types = lib.GetTypes();

                for (int i = 0; i < types.Length; i++)
                {
                    if (!IsPlugin(types[i]))
                    {
                        continue;
                    }

                    IGameComponent plugin = (IGameComponent)Activator.CreateInstance(types[i]);
                    if (needsInit)
                    {
                        plugin.Init(game);
                        plugin.Ready(game);
                    }

                    if (plugin == null)
                    {
                        throw new InvalidOperationException("Type " + types[i].Name + " returned null instance");
                    }
                    game.Components.Add(plugin);
                }
            } catch (Exception ex) {
                path = Path.GetFileNameWithoutExtension(path);
                ErrorHandler.LogError("PluginLoader.Load() - " + path, ex);
            }
        }
Пример #2
0
        public static void Load(string pluginName, bool needsInit)
        {
            try {
                string   dir   = Path.Combine(Program.AppDirectory, "plugins");
                string   path  = Path.Combine(dir, pluginName + ".dll");
                Assembly lib   = Assembly.LoadFrom(path);
                Type[]   types = lib.GetTypes();

                for (int i = 0; i < types.Length; i++)
                {
                    if (!IsPlugin(types[i]))
                    {
                        continue;
                    }

                    IGameComponent plugin = (IGameComponent)Activator.CreateInstance(types[i]);
                    if (needsInit)
                    {
                        plugin.Init(game);
                        plugin.Ready(game);
                    }

                    if (plugin == null)
                    {
                        throw new InvalidOperationException("Type " + types[i].Name + " returned null instance");
                    }
                    game.Components.Add(plugin);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("PluginLoader.Load() - " + pluginName, ex);
            }
        }