コード例 #1
0
ファイル: Program.cs プロジェクト: GwynethLlewelyn/restbot
        }         // 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);
                }
            }
        }