SharpMod.PluginManager.Load C# (CSharp) Method

Load() public static method

public static Load ( FileInfo fi ) : bool
fi System.IO.FileInfo
return bool
        public static bool Load(FileInfo fi)
        {
            try {
                Assembly asm = Assembly.LoadFile(fi.FullName);
                foreach (Type type in asm.GetTypes()) {
                    if (type.GetInterface("IPlugin") != null) {
                        IPlugin ip = (IPlugin)Activator.CreateInstance(type);
                        Load(ip);
                        return true;
                    }
                }
                return false;
            } catch {
                return false;
            }
        }

Same methods

PluginManager::Load ( IPlugin plugin ) : bool
PluginManager::Load ( string path ) : bool

Usage Example

Beispiel #1
0
        public static void Load(string filename)
        {
            ScriptSource script = engine.CreateScriptSourceFromFile(filename);
            ScriptScope  scope  = engine.CreateScope();

            object o = script.Execute(scope);

            if (o is IPlugin)
            {
                PluginManager.Load(o as IPlugin);
            }
            else
            {
                string  name, author, description;
                Version version;

                if (!scope.TryGetVariable <string> ("name", out name))
                {
                    name = "unknown";
                }
                if (!scope.TryGetVariable <string> ("author", out author))
                {
                    author = "unknown";
                }
                if (!scope.TryGetVariable <string> ("description", out description))
                {
                    description = "no description";
                }
                if (!scope.TryGetVariable <Version>("version", out version))
                {
                    version = new Version(0, 0);
                }

                RubyPlugin.UnloadDelegate unload;
                if (!scope.TryGetVariable <RubyPlugin.UnloadDelegate>("unload", out unload))
                {
                    unload = null;
                }

                PluginManager.Load(new RubyPlugin(name, author, description, version, unload));
            }
        }