CommandLineArgumentAttribute Class

Indicates a property or method of a class defines a command line argument.

Definition

Namespace: Ookii.CommandLine
Assembly: Ookii.CommandLine (in Ookii.CommandLine.dll) Version: 4.0.0+bb7ed9a8fdfd1cb21824750a8cf508863ad15086
C#
public sealed class CommandLineArgumentAttribute : Attribute
Inheritance
Object    Attribute    CommandLineArgumentAttribute

Remarks

If this attribute is applied to a property, the property's type determines the argument type, and the property will be set with either the set value or the default value after parsing is complete.

If an argument was not provided on the command line, and the default value is , the property will not be set and will remain at its initial value.

If this attribute is applied to a method, that method must have one of the following signatures:

C#
public static (void|bool|CancelMode) Method(ArgumentType value, CommandLineParser parser);
public static (void|bool|CancelMode) Method(ArgumentType value);
public static (void|bool|CancelMode) Method(CommandLineParser parser);
public static (void|bool|CancelMode) Method();

In this case, the ArgumentType type determines the type of values the argument accepts. If there is no value parameter, the argument will be a switch argument, and the method will be invoked if the switch is present, even if it was explicitly set to .

The method will be invoked as soon as the argument is parsed, before parsing the entire command line is complete.

The return type must be either Void, Boolean or CancelMode. Using Void is equivalent to returning CancelModeNone, and when using Boolean, returning is equivalent to returning CancelModeAbort.

Unlike using the CancelParsing property, canceling parsing with the return value does not automatically print the usage help when using the CommandLineParserTParseWithErrorHandling method, the CommandLineParserParseT(String, ParseOptions) method or the CommandManager class. Instead, it must be requested using by setting the CommandLineParserHelpRequested property to in the target method.

Constructors

CommandLineArgumentAttribute Initializes a new instance of the CommandLineArgumentAttribute class using the specified argument name.

Properties

ArgumentName Gets the name of the argument.
CancelParsing Gets or sets a value that indicates whether argument parsing should be canceled if this argument is encountered.
DefaultValue Gets or sets the default value to be assigned to the property if the argument is not supplied on the command line.
IncludeDefaultInUsageHelp Gets or sets a value that indicates whether the argument's default value should be shown in the usage help.
IsHidden Gets or sets a value that indicates whether the argument is hidden from the usage help.
IsLong Gets or sets a value that indicates whether the argument has a long name.
IsPositional Gets or sets a value that indicates that an argument is positional.
IsRequired Gets or sets a value indicating whether the argument is required.
IsShort Gets or sets a value that indicates whether the argument has a short name.
Position Gets or sets the relative position of a positional argument.
ShortName Gets or sets the argument's short name.
TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute.
(Inherited from Attribute)

Methods

EqualsReturns a value that indicates whether this instance is equal to a specified object.
(Inherited from Attribute)
GetHashCodeReturns the hash code for this instance.
(Inherited from Attribute)
GetTypeGets the Type of the current instance.
(Inherited from Object)
IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.
(Inherited from Attribute)
MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object.
(Inherited from Attribute)
ToStringReturns a string that represents the current object.
(Inherited from Object)

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also