Click or drag to resize

CommandLineParserParseT Method (String)

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
)
where T : class

Parameters

args
Type: SystemString
The command line arguments.

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
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, it prints error and usage information to the standard error and output streams using a LineWrappingTextWriter.

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