MultiValueSeparatorAttribute Class

Specifies a separator for the values of multi-value arguments.

Definition

Namespace: Ookii.CommandLine
Assembly: Ookii.CommandLine (in Ookii.CommandLine.dll) Version: 4.2.0+a4d3631e4dcc0970081ed435288efdebc1325f83
C#
public class MultiValueSeparatorAttribute : Attribute
Inheritance
Object    Attribute    MultiValueSeparatorAttribute

Remarks

Normally, you need to supply the argument multiple times to set multiple values, e.g. by using -Sample Value1 -Sample Value2. If you specify the MultiValueSeparatorAttribute attribute, it allows you to specify multiple values with a single argument by using a separator.

There are two ways you can use separators for multi-value arguments: a white-space separator, or an explicit separator string.

You enable the use of white-space separators with the MultiValueSeparatorAttribute constructor. A multi-value argument that allows white-space separators is able to consume multiple values from the command line that follow it. All values that follow the name, up until the next argument name, are considered values for this argument.

For example, if you use -Sample Value1 Value2 Value3, all three arguments after -Sample are taken as values. In this case, it's not possible to supply any positional arguments until another named argument has been supplied.

Using white-space separators will not work if the CommandLineParserAllowWhiteSpaceValueSeparator property is or if the argument is a multi-value switch argument.

Using the MultiValueSeparatorAttribute(String) constructor, you instead specify an explicit character sequence to be used as a separator. For example, if the separator is set to a comma, you can use -Sample Value1,Value2.

  Note

If you specify an explicit separator for a multi-value argument, it will not be possible to use the separator in the individual argument values. There is no way to escape it.

Even if the MultiValueSeparatorAttribute is specified it is still possible to use multiple arguments to specify multiple values. For example, using a comma as the separator, -Sample Value1,Value2 -Sample Value3 will mean the argument "Sample" has three values.

Constructors

MultiValueSeparatorAttribute Initializes a new instance of the MultiValueSeparatorAttribute class using white-space as the separator.
MultiValueSeparatorAttribute(String) Initializes a new instance of the MultiValueSeparatorAttribute class.

Properties

Separator Gets the separator for the values of a multi-value argument.
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)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
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)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
ToStringReturns a string that represents the current object.
(Inherited from Object)

Thread Safety

Static members of this type are safe for multi-threaded operations. Instance members of this type are safe for multi-threaded operations.

See Also