How can you access the Value property of a CommandLine Parsed ?
Trying to use the CommandLineParser
The wiki section on Parsing says the instance of T can be access through the Value
property ...
If parsing succeeds, you'll get a derived Parsed type that exposes an instance of T through its Value property.
But I can't see any Value
property on the parserResult
, only a Tag
...
ParserResult<Options> parserResult = Parser.Default.ParseArguments<Options>(args);
WriteLine(parserResult.Tag);
And I know I'm missing something as if I debug, I can see the Value
property ???
To get to parsed object (or errors in case parsing failed), you can do this:
ParserResult<Options> parserResult = Parser.Default.ParseArguments<Options>(args);
if (parserResult.Tag == ParserResultType.Parsed) {
var options = ((Parsed<Options>)parserResult).Value;
}
else {
var errors = ((NotParsed<Options>)parserResult).Errors;
}
That's questionable design, but in general you are not expected to do it like this anyway, expected usage is more like:
Parser.Default.ParseArguments<Options>(args)
.WithParsed(options => ...)
.WithNotParsed(errors => ...)IEnumerable<Error>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With