CommandLineArgumentAttributeCancelParsing Property

Gets or sets a value that indicates whether argument parsing should be canceled if this argument is encountered.

Definition

Namespace: Ookii.CommandLine
Assembly: Ookii.CommandLine (in Ookii.CommandLine.dll) Version: 3.1.1
C#
public bool CancelParsing { get; set; }

Property Value

Boolean
if argument parsing should be canceled after this argument; otherwise, . The default value is .

Remarks

If this property is , the CommandLineParser will stop parsing the command line arguments after seeing this argument, and return from the Parse(String, Int32) method or one of its overloads. Since no instance of the arguments type is returned, it's not possible to determine argument values, or which argument caused the cancellation, except by inspecting the Arguments property.

This property is most commonly useful to implement a "-Help" or "-?" style switch argument, where the presence of that argument causes usage help to be printed and the program to exit, regardless of whether the rest of the command line is valid or not.

The ParseWithErrorHandling method and the ParseT(String, ParseOptions) static helper method will print usage information if parsing was canceled through this method.

Canceling parsing in this way is identical to handling the ArgumentParsed event and setting Cancel to .

It's possible to prevent cancellation when an argument has this property set by handling the ArgumentParsed event and setting the OverrideCancelParsing property to .

See Also