Skip to content

Retrieving Values & Arguments

Jan Michelfeit edited this page Feb 2, 2016 · 2 revisions

Option parameters and non-option arguments can be retrieved after you set program options and call EasyOpt.Parse() method.

To obtain option values, query the corresponding Option<T> or Parameter<T> object.

Option<T>.IsPresent property is true when the option was present among the parsed arguments, false otherwise.

bool isVerbose = verbose.IsPresent;

To retrieve a parameter value, use Parameter<T>.Value property. If the value hasn't been specified in the arguments, it returns the default value.

int maxLineWidth = lineWidthParam.Value;

Since in case of options without a parameter, one is usually interested in IsPresent value and in case of options with a parameter, one is interested in the parameter's value, you can easily access the relevant information uniformly with Option<T>.Value property:

bool isVerbose = verbose.Value;
int maxLineWidth = lineWidth.Value;

Non-option arguments can be retrieved as a string array:

String[] arguments = parser.GetArguments();

The arguments are listed in the same order as they were on the command line. GetArguments() returns a static copy of the arguments array.

Clone this wiki locally