-
Notifications
You must be signed in to change notification settings - Fork 290
Best Practices
gsscoder edited this page Jan 25, 2013
·
15 revisions
If your application cannot recover after a failed parsing, entrust strict parsing.
var options = new Options();
// Parse in 'strict mode', success or quit
if (CommandLineParser.Default.ParseArgumentsStrict(args, options))
{
// Domain logic here
}
This feature is available from Version 1.9.4.107 beta as stated here.
Before Version 1.9.4.201 beta all options non mapped with a short or long name could have been read with ValueListAttribute
.
If values are of different type and you will handle these individually, embrace ValueOptionAttribute
.
class Options
{
[ValueOption]
public uint Count { get; set; }
[ValueOption]
public double? Size { get; set; }
[ValueOption]
public string Content { get; set; }
}
Values mapped with this attribute are mapped to properties respecting input and declaration order. ValueOptionAttribute
can live side by side with ValueListAttribute
and takes precedence over the latter.
If input value cannot be converted to target property, parsing will fail.