public SetValue ( string value ) : void | ||
value | string | The value that should be assigned to the argument. |
return | void |
/// <summary> /// Parse the argument list using the /// </summary> /// <param name="args"></param> private void ParseArgumentList(string[] args) { if (args != null) { foreach (string argument in args) { if (argument.Length > 0) { switch (argument[0]) { case '-': case '/': int endIndex = argument.IndexOfAny(new char[] { ':', '+', '-' }, 1); string option = argument.Substring(1, endIndex == -1 ? argument.Length - 1 : endIndex - 1); string optionArgument; if (option.Length + 1 == argument.Length) { optionArgument = null; } else if (argument.Length > 1 + option.Length && argument[1 + option.Length] == ':') { optionArgument = argument.Substring(option.Length + 2); } else { optionArgument = argument.Substring(option.Length + 1); } CommandLineArgument arg = _argumentCollection[option]; if (arg == null) { throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture, "Unknown argument '{0}'", argument)); } else { // check if argument is obsolete Attribute[] attribs = (Attribute[])arg.Property.GetCustomAttributes( typeof(ObsoleteAttribute), false); if (attribs.Length > 0) { ObsoleteAttribute obsoleteAttrib = (ObsoleteAttribute)attribs[0]; string message = string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1177"), option, obsoleteAttrib.Message); if (obsoleteAttrib.IsError) { throw new CommandLineArgumentException(message); } else { Console.WriteLine(string.Empty); Console.WriteLine("Warning: " + message); Console.WriteLine(string.Empty); } } if (arg.IsExclusive && args.Length > 1) { throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture, "Commandline argument '-{0}' cannot be combined with other arguments.", arg.LongName)); } else { arg.SetValue(optionArgument); } } break; case '@': if (_supportsResponseFile) { string responseFile = argument.Substring(1, argument.Length - 1); if (!File.Exists(responseFile)) { throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture, "unable to open response file \"{0}\"", responseFile)); } // load file and parse it. ProcessResponseFile(responseFile); break; } continue; default: if (_defaultArgument != null) { _defaultArgument.SetValue(argument); } else { throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture, "Unknown argument '{0}'", argument)); } break; } } } } }