Click or drag to resize

CommandLineParserParseT Method (String, ParseOptions)

Parses the specified command line arguments into the specified type.

Namespace:  Ookii.CommandLine
Assembly:  Ookii.CommandLine (in Ookii.CommandLine.dll) Version: 2.4.0
Syntax
public static T Parse<T>(
	string[] args,
	ParseOptions options
)
where T : class

Parameters

args
Type: SystemString
The command line arguments.
options
Type: Ookii.CommandLineParseOptions
The options that control parsing behavior.

Type Parameters

T
The type defining the command line arguments.

Return Value

Type: T
An instance of the type T, or if an error occurred or if argument parsing was cancelled by the ArgumentParsed event handler or the CancelParsing property.
Exceptions
ExceptionCondition
ArgumentNullExceptionoptions is .
ArgumentNullExceptionargs is .
CommandLineArgumentException Too many positional arguments were supplied, a required argument was not supplied, an unknown argument name was supplied, no value was supplied for a named argument, an argument was supplied more than once and AllowDuplicateArguments is , or one of the argument values could not be converted to the argument's type.
Remarks

This is a convenience function that instantiates a CommandLineParser, calls Parse(String), and returns the result. If an error occurs or parsing is cancelled, it prints error and usage according to Error and Out respectively.

If the Out property or Error property is , output is written to a LineWrappingTextWriter for the standard output and error streams respectively, wrapping at the console's window width. When the console output is redirected to a file, Microsoft .Net will still report the console's actual window width, but on Mono the value of the WindowWidth property will be 0. In that case, the usage information will not be wrapped.

If the Out property is instance of the LineWrappingTextWriter class, this method indents additional lines for the usage syntax and argument descriptions according to the values specified by the CreateShellCommandOptions, unless the MaximumLineLength property is less than 30.

If you want more control over the parsing process, including custom error/usage output or handling the ArgumentParsed event, do not use this function; instead perform these steps manually.

See Also