Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }