Ejemplo n.º 1
0
        public static List <SlashModuleInfo> InstantiateSubModules(Type rootModule, SlashModuleInfo rootModuleInfo, SlashCommandService slashCommandService, IServiceProvider services)
        {
            // Instantiate all of the nested modules.
            var commandGroups = new List <SlashModuleInfo>();

            foreach (var commandGroupType in rootModule.GetNestedTypes())
            {
                if (!TryGetCommandGroupAttribute(commandGroupType, out var commandGroup))
                {
                    continue;
                }
                //var commandGroupTypeInfo = commandGroupType.GetTypeInfo();

                var groupInfo = new SlashModuleInfo(slashCommandService, services);
                groupInfo.SetModuleType(commandGroupType);

                //var instance = ReflectionUtils.CreateObject<ISlashCommandModule>(commandGroupTypeInfo, slashCommandService, services);
                //object instance = commandGroupType.GetConstructor(Type.EmptyTypes).Invoke(null);
                //groupInfo.SetCommandModule(instance);

                groupInfo.MakeCommandGroup(commandGroup, rootModuleInfo);
                groupInfo.MakePath();
                groupInfo.isGlobal = IsCommandModuleGlobal(commandGroupType);

                groupInfo.SetSubCommandGroups(InstantiateSubModules(commandGroupType, groupInfo, slashCommandService, services));
                commandGroups.Add(groupInfo);
            }

            return(commandGroups);
        }