public static T Parse<T>(
string[] args,
ParseOptions? options = null
)
where T : class
Public Shared Function Parse(Of T As Class) (
args As String(),
Optional options As ParseOptions = Nothing
) As T
Dim args As String()
Dim options As ParseOptions
Dim returnValue As T
returnValue = CommandLineParser.Parse(args, options)
public:
generic<typename T>
where T : ref class
static T Parse(
array<String^>^ args,
ParseOptions^ options = nullptr
)
This is a convenience function that instantiates a CommandLineParser<T>, calls the ParseWithErrorHandling() method, and returns the result. If an error occurs or parsing is canceled, it prints errors to the ParseOptions.Error stream, and usage help to the UsageWriter if the HelpRequested property is true. It then returns null.
If the ParseOptions.Error parameter is null, 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 Console.WindowWidth.
Color is applied to the output depending on the value of the UsageWriter.UseColor property, the ParseOptions.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 use the instance CommandLineParser<T>.Parse() or CommandLineParser<T>.ParseWithErrorHandling() method.
This method uses reflection to determine the arguments defined by the type T at runtime, unless the type has the GeneratedParserAttribute applied. For a type using that attribute, you can also use the generated static IParserProvider<TSelf>.CreateParser(ParseOptions) or IParser<TSelf>.Parse(ParseOptions) methods on the arguments class instead.
ArgumentNullException | args is null. |
CommandLineArgumentException | An error occurred parsing the command line. Check the CommandLineArgumentException.Category property for the exact reason for the error. |
NotSupportedException | The CommandLineParser cannot use T as the command line arguments type, because it violates one of the rules concerning argument names or positions, or has an argument type that cannot be parsed. |