Skip to content
gsscoder edited this page Feb 25, 2013 · 15 revisions

Strict Parsing

If your application cannot recover after a failed parsing, entrust strict parsing.

var options = new Options();
// Parse in 'strict mode', success or quit
if (CommandLine.Parser.Default.ParseArgumentsStrict(args, options))
{
  // Domain logic here
}

This is not only a better formalism. With strict parsing you don't need to define any GetUsage(...), HelpText::AutoBuild(...) will be invoked for you. As for other features, if GetUsage(...) is defined the library will execute it.

This feature is available from Version 1.9.4.107 beta as stated here.

Map Heterogeneous Values

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(0)]
  public uint Count { get; set; }

  [ValueOption(1)]
  public double? Size { get; set; }

  [ValueOption(2)]
  public string Content { get; set; }
}

Values mapped with this attribute are mapped to properties correlating input and index order defined in constructor. 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.

Remarks: at the moment if you omit the index the default is set to zero. The constructor without parameters is marked Obsolete and will be removed in the next stable.