Пример #1
0
        public static ParameterHelpData FromParameterInfo(ParameterInfo parameter)
        {
            ParameterHelpData ret = new ParameterHelpData
            {
                Name       = parameter.Name,
                Summary    = parameter.Summary,
                Type       = parameter.Type.Name,
                IsOptional = parameter.IsOptional
            };

            return(ret);
        }
Пример #2
0
        public static ParameterHelpData FromParameterInfo(ParameterInfo parameter)
        {
            ParameterHelpData ret = new ParameterHelpData
            {
                Name       = parameter.Name,
                Summary    = parameter.Summary,
                Type       = parameter.Type.Name,
                IsOptional = parameter.IsOptional,
                Options    = parameter.Type.IsEnum ? parameter.Type.GetEnumNames() : new string[0]
            };

            return(ret);
        }
Пример #3
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);
        }
Пример #4
0
        public static ParameterHelpData FromParameterInfo(ParameterInfo parameter)
        {
            var ret = new ParameterHelpData
            {
                Name       = parameter.Name,
                Summary    = parameter.Summary,
                Type       = parameter.Type.Name,
                IsOptional = parameter.IsOptional,
                Options    = parameter.Type.IsEnum
                    ? parameter.Type.GetEnumNames()
                    : Array.Empty <string>(),
            };

            return(ret);
        }
Пример #5
0
        public static IEnumerable <CommandHelpData> FromCommandInfo(CommandInfo command)
        {
            List <CommandHelpData> ret = new List <CommandHelpData>();

            foreach (var alias in command.Aliases)
            {
                var data = new CommandHelpData
                {
                    Alias   = alias,
                    Name    = command.Name,
                    Summary = command.Summary
                };

                foreach (var param in command.Parameters)
                {
                    data.Parameters.Add(ParameterHelpData.FromParameterInfo(param));
                }

                ret.Add(data);
            }

            return(ret);
        }
Пример #6
0
        public static ParameterHelpData FromParameterInfo(ParameterInfo parameter)
        {
            bool   isNullable = parameter.Type.IsGenericType && parameter.Type.GetGenericTypeDefinition() == typeof(Nullable <>);
            var    paramType  = isNullable ? parameter.Type.GetGenericArguments()[0] : parameter.Type;
            string typeName   = paramType.Name;

            if (paramType.IsInterface && paramType.Name.StartsWith('I'))
            {
                typeName = typeName.Substring(1);
            }

            var ret = new ParameterHelpData
            {
                Name       = parameter.Name,
                Summary    = parameter.Summary,
                Type       = typeName,
                IsOptional = isNullable || parameter.IsOptional,
                Options    = parameter.Type.IsEnum
                    ? parameter.Type.GetEnumNames()
                    : Array.Empty <string>(),
            };

            return(ret);
        }