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: 3.0.0
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 bool Method(ArgumentType value, CommandLineParser parser);
public static bool Method(ArgumentType value);
public static bool Method(CommandLineParser parser);
public static bool Method();
public static void Method(ArgumentType value, CommandLineParser parser);
public static void Method(ArgumentType value);
public static void Method(CommandLineParser parser);
public static void 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. Return to cancel parsing, in which case the remaining arguments will not be parsed and the Parse(String, Int32) method returns .

Unlike using the CancelParsing or ArgumentParsed event, canceling parsing with the return value does not automatically print the usage help when using the ParseT(String, Int32, ParseOptions) method or the CommandManager class. Instead, it must be requested using by setting the HelpRequested property to .

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.
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.
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 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)
ValueDescription Gets or sets a short description of the property's value to use when printing usage information.

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