CommandLineParserParseT(ParseOptions) Method

Parses the arguments returned by the GetCommandLineArgs method using the type T.

Definition

Namespace: Ookii.CommandLine
Assembly: Ookii.CommandLine (in Ookii.CommandLine.dll) Version: 3.1.1
C#
public static T Parse<T>(
	ParseOptions? options = null
)
where T : class

Parameters

options  ParseOptions  (Optional)
The options that control parsing behavior and usage help formatting. If , the default options are used.

Type Parameters

T
The type defining the command line arguments.

Return Value

T
An instance of the type T, or if an error occurred, or argument parsing was canceled by the CancelParsing property or a method argument that returned .

Remarks

This is a convenience function that instantiates a CommandLineParser, calls the Parse method, and returns the result. If an error occurs or parsing is canceled, it prints errors to the Error stream, and usage help to the UsageWriter if the HelpRequested property is . It then returns .

If the Error parameter is , output is written to a LineWrappingTextWriter for the standard error stream, wrapping at the console's window width. If the stream is redirected, output may still be wrapped, depending on the value returned by WindowWidth.

Color is applied to the output depending on the value of the UseColor property, the UseErrorColor property, and the capabilities of the console.

If you want more control over the parsing process, including custom error/usage output or handling the ArgumentParsed event, you should manually create an instance of the CommandLineParserT class and call its Parse method.

Exceptions

CommandLineArgumentException An error occurred parsing the command line. Check the Category property for the exact reason for the error.

See Also