コード例 #1
0
        public static ModuleHelpData FromModuleInfo(ModuleInfo module)
        {
            string moduleName = module.Name;

            var suffixPosition = moduleName.IndexOf("Module", StringComparison.Ordinal);

            if (suffixPosition > -1)
            {
                moduleName = module.Name.Substring(0, suffixPosition).Humanize();
            }

            moduleName = moduleName.ApplyCase(LetterCasing.Title);

            var ret = new ModuleHelpData
            {
                Name     = moduleName, Summary = string.IsNullOrWhiteSpace(module.Summary) ? "No Summary" : module.Summary,
                Commands = module.Commands.Where(x => !ShouldBeHidden(x))
                           .Select(x => CommandHelpData.FromCommandInfo(x))
                           .ToArray(),
                HelpTags = module.Attributes.OfType <HelpTagsAttribute>().SingleOrDefault()?.Tags
                           ?? Array.Empty <string>()
            };

            return(ret);

            bool ShouldBeHidden(CommandInfo command)
            {
                return(command.Preconditions.Any(x => x is RequireOwnerAttribute) ||
                       command.Attributes.Any(x => x is HiddenAttribute));
            }
        }
コード例 #2
0
        public static CommandHelpData FromCommandInfo(CommandInfo command)
        {
            var ret = new CommandHelpData
            {
                Name       = command.Name, Summary = command.Summary, Aliases = command.Aliases,
                Parameters = command.Parameters.Select(x => ParameterHelpData.FromParameterInfo(x)).ToArray()
            };

            return(ret);
        }