Thetype exposes the following members.
Constructs an instance optionally expanding any response files specified in the arguments passed.
Returns the array of command line values (items that are not command line options).
Determines if the --help command line option is present.
Returns an item from the command line based on its position.
Returns the array of command line arguments (including both command line options and values).
Returns the command line options as a dictionary of option name/value tuples.
Adds an option definition to the command line and returns the definition so its default value may be set if desired.
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Expands the command line by processing items beginning with '@' as input files.
Checks the argument passed for wildcards and expands them into the appopriate set of matching file names.
Formats an array of objects into a form suitable for passing to a process on the command line by adding double quotes around any values with embedded spaces.
Enumerates the command line arguments beginning at the specified index.
Determines whether an option is present on the command line.
Serves as the default hash function.(Inherited from Object.)
Returns the value associated with a command line option if the option was present on the command line otherwise, the specified default value will be returned.
Returns all of the values a command line option that appears multiple times in the command.
Gets the Type of the current instance.(Inherited from Object.)
Determines if an option was present on the command line.
Parses the argument string passed into ainstance, dealing with quoted parameters, etc.
Returns a newwhich includes all of the command line options and the arguments starting at the position passed to the end of the command line, essentially shifting arguments to the left.
Splits the command line into two parts, the command line to the left of the first specified item (defaults to "--") and the command line to the right of it.
Determines whether the command line starts with the specified arguments.
Renders the command line as a string suitable for presenting to a process or a command line shell. Arguments that include spaces will be enclosed in double quotes.(Overrides ObjectToString.)
Command lines may consist of zero or more items. Items that begin with the dash (-) character are considered to be command line options. Items that begin with an at sign (@) can be considered to be response files, and all other items are considered to be command line arguments.
|The "-" and "--" items (without an option name are considered arguments, not options.|
The static ExpandFiles(String) method can be used to process response files specified in a command line. Response files are specified by prepending a '@' character to the name of a text file and then treating each line of the file as a command line item.
The static ExpandWildcards(String) method can be used to expand file names with wildcard characters into the set of actual files that match the pattern.
Theclass can also handles parsing of items as command line options.
will be parsed into name/value pairs and will be available for lookup via the string keyed indexer. Options that specify no value will be assigned an empty string value.
|Command line option names are case sensitive.|
The class will also make all command line items available via the integer keyed indexer which will return items based on their position on the command line and also via the Items property. Command line items that are not command, are available via the Arguments property. Options can be looked up via the GetOption(String, String) and GetOptionValues(String) overrides.
DefineOption(String) method. This associates one or more option names with an optional default value.also supports the definition of long and short forms of options with optional default values using the
You can use this easily implement the short and long forms of options as well as to centralize the specification of option default values.
var commandLine = new CommandLine(args); commandLine.DefineOption("-q", "--quiet"); commandLine.DefineOption("-k", "--key").Default = "none"; // These calls both return the option value for "-q" or "--quiet". // Since no default value was set, the default value will be the // empty string. commandLine.GetOption("-q"); commandLine.GetOption("--quiet"); // These calls both return the option value for "-k" or "--key". // The default value will be "none". commandLine.GetOption("-k"); commandLine.GetOption("--key");
|This class assumes that the position of command line options doesn't matter, which is somewhat simplistic. In particular, the Shift(Int32, String) method actually relocates all of the options to the beginning of the shifted command line.|