예제 #1
0
        public string ToString(CommandExectionContext context, string argument = null)
        {
            switch (Type)
            {
            case ParameterType.DefaultValue:
            case ParameterType.NotRequired:
            {
                return((argument ?? DefaultValue) ?? string.Empty);
            }

            case ParameterType.Required:
            {
                if (string.IsNullOrWhiteSpace(argument))
                {
                    throw new ArgumentNullException(nameof(argument));
                }

                return(argument);
            }

            case ParameterType.PlayerName:
            {
                return(context?.Player?.Name ?? "None");
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(Type));
            }
        }
        public string[] Convert(CommandExectionContext ctx, string[] args)
        {
            if (args.Length < _fewestParamCount)
            {
                throw new LackOfArgumentException("语法无效!正确语法:" + TShockAPI.Commands.Specifier + ParameterHelpText);
            }

            var values = new string[Parameters.Length];

            for (var index = 0; index < values.Length; index++)
            {
                values[index] = Parameters[index].ToString(ctx, args.ElementAtOrDefault(index));
            }

            return(FormatLines.Select(x => string.Format(x, values /*.Select(v => (object)v).ToArray()*/)).ToArray());
        }