} // end ParseArguments /// <summary> /// Register all RestPlugins to the RestBot static plugin dictionary /// </summary> /// <param name="assembly">Given assembly to search for</param> static void RegisterAllCommands(Assembly assembly) { foreach (Type t in assembly.GetTypes()) { try { if (t.IsSubclassOf(typeof(RestPlugin))) { ConstructorInfo?info = t.GetConstructor(Type.EmptyTypes); // ask for parameter-less constructor for this class, if it exists (gwyneth 20220425) if (info == null) { // Not a serious warning, some plugins might be incorrectly configured but still work well DebugUtilities.WriteWarning($"Couldn't get constructor without parameters for plugin {t.GetType().Name}!"); } else { RestPlugin plugin = (RestPlugin)info.Invoke(new object[0]); RestBot.AddPlugin(plugin); } } } catch (Exception e) { DebugUtilities.WriteError(e.Message); } } }
/// <summary> /// Add a new plugin to the system. /// </summary> /// <param name="Plugin">Plugin object</param> public static void AddPlugin(RestPlugin Plugin) { lock (Plugins) { if (!Plugins.ContainsKey(Plugin.MethodName)) { Plugins.Add(Plugin.MethodName, Plugin); } } }
public static void AddPlugin(RestPlugin Plugin) { lock (Plugins) { if (!Plugins.ContainsKey(Plugin.MethodName)) Plugins.Add(Plugin.MethodName, Plugin); } }