private static CommandArgumentHelp GetInvalidArgumentString(Type argumentType, CommandArgument argument) { var cmdLine = string.Join(" ", CommandLine.Args); var message = argument.IsParameter() ? string.Format("Invalid argument \"{0}\" at parameter index {1} in command line \"{2}\"", argument.Token, argument.ParameterNumber, cmdLine) : string.Format("Invalid command \"{0}\" at index {1} in command line \"{2}\"", argument.Token, cmdLine.IndexOf(argument.Token), cmdLine); return new CommandArgumentHelp(argumentType, message); }
private static CommandArgumentHelp GetInvalidArgumentString(Type argumentType, CommandArgument argument) { var cmdLine = string.Join(" ", CommandLine.Args); var message = argument.IsParameter() ? Strings.InvalidCommandLineArgument(argument.Token, argument.ParameterIndex, cmdLine) : Strings.InvalidCommandLineCommand( argument.Token, cmdLine.IndexOf(argument.Token, StringComparison.InvariantCulture), cmdLine); return new CommandArgumentHelp(argumentType, message); }
public void SetValue(object argument, CommandArgument cmd) { // Argument already supplied if (!IsCollection() && ArgumentSupplied) { throw new CommandLineArgumentInvalidException(argument.GetType(), cmd); } Argument = cmd; if (Property.PropertyType == typeof(bool)) { Property.SetValue(argument, GetBoolValue(cmd), null); } else if (Property.PropertyType == typeof(int)) { Property.SetValue(argument, Convert.ToInt32(cmd.Value), null); } else if (Property.PropertyType == typeof(DateTime)) { Property.SetValue(argument, Convert.ToDateTime(cmd.Value), null); } else if (Property.PropertyType == typeof(string)) { Property.SetValue(argument, cmd.Value, null); } else if (Property.PropertyType == typeof(List<string>)) { var list = (List<string>)Property.GetValue(argument, null) ?? new List<string>(); list.Add(cmd.Value); Property.SetValue(argument, list, null); } else { throw new CommandLineException( new CommandArgumentHelp( argument.GetType(), Strings.UnsupportedPropertyType(Property.PropertyType))); } ArgumentSupplied = true; }
/// <summary> /// Returns a boolean value from a command switch /// </summary> /// <param name="cmd"> The command switch </param> /// <returns> A boolean value based on the switch and value </returns> private static bool GetBoolValue(CommandArgument cmd) { return string.IsNullOrWhiteSpace(cmd.SwitchOption) || cmd.SwitchOption.Trim() == "+"; }
public CommandLineArgumentInvalidException(Type argumentType, CommandArgument argument) : base(GetInvalidArgumentString(argumentType, argument)) { }
private static CommandArgumentHelp GetInvalidArgumentString(Type argumentType, CommandArgument argument) { var cmdLine = string.Join(" ", CommandLine.Args); var message = argument.IsParameter() ? Strings.InvalidCommandLineArgument(argument.Token, argument.ParameterIndex, cmdLine) : Strings.InvalidCommandLineCommand( argument.Token, cmdLine.IndexOf(argument.Token, StringComparison.InvariantCulture), cmdLine); return(new CommandArgumentHelp(argumentType, message)); }
/// <summary> /// Returns a boolean value from a command switch /// </summary> /// <param name="cmd"> The command switch </param> /// <returns> A boolean value based on the switch and value </returns> private static bool GetBoolValue(CommandArgument cmd) { return(string.IsNullOrWhiteSpace(cmd.SwitchOption) || cmd.SwitchOption.Trim() == "+"); }
private static CommandArgumentHelp GetInvalidArgumentString(Type argumentType, CommandArgument argument) { var cmdLine = string.Join(" ", CommandLine.Args); var message = argument.IsParameter() ? string.Format( "Invalid argument \"{0}\" at parameter index {1} in command line \"{2}\"", argument.Token, argument.ParameterIndex, cmdLine) : string.Format( "Invalid command \"{0}\" at index {1} in command line \"{2}\"", argument.Token, cmdLine.IndexOf(argument.Token), cmdLine); return(new CommandArgumentHelp(argumentType, message)); }