public static CommandInfo GenerateCommandInfo <T>(T command) where T : ServerCommand
        {
            T           defaultInstance = Activator.CreateInstance <T>();
            CommandInfo commandInfo     = new CommandInfo();

            commandInfo.Name        = command.type;
            commandInfo.Description = "";
            commandInfo.Arguments   = new Dictionary <string, CommandArgumentInfo>();

            FieldInfo[] args = GetCommandArguments <T>();
            foreach (FieldInfo fieldInfo in args)
            {
                CommandArgumentInfo argInfo = new CommandArgumentInfo();

                argInfo.Name = fieldInfo.Name;
                argInfo.Type = GetFriendlyFieldNameType(fieldInfo);

                argInfo.DefaultValue = fieldInfo.GetValue(defaultInstance);
                argInfo.IsRequired   = argInfo.DefaultValue == null;

                commandInfo.Arguments.Add(argInfo.Name, argInfo);
            }

            return(commandInfo);
        }
 public ArgumentInfo Create(CommandArgumentInfo argument)
 {
     return(new ArgumentInfo
     {
         Name = argument.Name,
         Description = "Empty",
         ExampleValues = "Empty"
     });
 }
示例#3
0
        private static object ParseArgument(CommandArgumentInfo argumentInfo, string argument)
        {
            argument = argument ?? string.Empty;

            switch (argumentInfo.DataType)
            {
            case CommandArgumentDataType.String:
                return(argument);

            case CommandArgumentDataType.Integer:
                return(int.TryParse(argument, NumberStyles.Any, CultureInfo.InvariantCulture, out var intValue) ? intValue : 0);

            default:
                throw new InvalidEnumArgumentException();
            }
        }