EnumConverter Class

A converter for arguments with enumeration values.

Definition

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

Remarks

This converter performs a case insensitive conversion, and accepts the name of an enumeration value or a number representing the underlying type of the enumeration. Comma-separated values that will be combined using bitwise-or are also accepted, regardless of whether the enumeration uses the FlagsAttribute attribute. When using a numeric value, the value does not need to be one of the defined values of the enumeration.

Use the ValidateEnumValueAttribute attribute to alter these behaviors. Applying that attribute will ensure that only values defined by the enumeration are allowed. The ValidateEnumValueAttributeAllowCommaSeparatedValues property can be used to control the use of multiple values, and the ValidateEnumValueAttributeAllowNumericValues property controls the use of numbers instead of names. Set the ValidateEnumValueAttributeCaseSensitive property to to enable case sensitive conversion.

If conversion fails, the converter will check the ValidateEnumValueAttributeIncludeValuesInErrorMessage property to see whether or not the enumeration's defined values should be listed in the error message. If the argument does not have the ValidateEnumValueAttribute attribute applied, the enumeration's values will be listed in the message.

Constructors

EnumConverter Initializes a new instance of the EnumConverter for the specified enumeration type.

Properties

EnumType Gets the enumeration type that this converter converts to.

Methods

Convert(ReadOnlySpanChar, CultureInfo, CommandLineArgument) Converts a string span to the enumeration type.
(Overrides ArgumentConverterConvert(ReadOnlySpanChar, CultureInfo, CommandLineArgument))
Convert(String, CultureInfo, CommandLineArgument) Converts a string to the enumeration type.
(Overrides ArgumentConverterConvert(String, CultureInfo, CommandLineArgument))
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
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