public class ValidateEnumValueAttribute : ArgumentValidationWithHelpAttribute
Public Class ValidateEnumValueAttribute
Inherits ArgumentValidationWithHelpAttribute
Dim instance As ValidateEnumValueAttribute
public ref class ValidateEnumValueAttribute : public ArgumentValidationWithHelpAttribute
Conversion from a string to an enumeration value can use either the name of the enumeration member, the numeric value of the member, or a comma-separated list of values. By default, however, the EnumConverter class only allows names of enumeration members, and comma-separated values are only allowed if the enumeration has the FlagsAttribute attribute.
Using the ValidateEnumValueAttribute, you can change these behaviors. You can allow numeric values with the AllowNumericValues property, and you can force whether comma-separated values are allowed with the AllowCommaSeparatedValues property.
If numeric values are allowed, they are restricted to values that are defined in the enumeration, unless the enumeration has the FlagsAttribute applied or you set the AllowNonDefinedValues property to TriStateTrue. In that case, for example using the DayOfWeek enumeration, converting a string value of "9" would result in a value of (DayOfWeek)9, even though there is no enumeration member with that value.
In addition, this validator provides usage help listing all the possible values. If the enumeration has a lot of values, you may wish to turn this off by setting the ArgumentValidationWithHelpAttributeIncludeInUsageHelp property to . Similarly, you can avoid listing all the values in the error message by setting the IncludeValuesInErrorMessage property to .
If this validator is used without changing any of its properties on an argument that uses the default EnumConverter, its only effect is to list the values in the usage help. The default behavior of the EnumConverter class is the same as the defaults of this validator.
ValidateEnumValueAttribute | Initializes a new instance of the ValidateEnumValueAttribute class |
AllowCommaSeparatedValues | Gets or sets a value that indicates whether the value provided by the user can use commas to provide multiple values that will be combined with bitwise-or. |
AllowNonDefinedValues | Gets or sets a value that indicates whether values that do not match one of the enumeration's defined values are allowed. |
AllowNumericValues | Gets or sets a value that indicates whether the value provided by the user can the underlying numeric type of the enumeration. |
CaseSensitive | Gets or sets a value that indicates whether enumeration value conversion is case sensitive. |
ErrorCategory |
Gets the error category used for the CommandLineArgumentException when
validation fails.
(Inherited from ArgumentValidationAttribute) |
IncludeInUsageHelp |
Gets or sets a value that indicates whether this validator's help should be included
in the argument's description.
(Inherited from ArgumentValidationWithHelpAttribute) |
IncludeValuesInErrorMessage | Gets or sets a value that indicates whether the possible values of the enumeration should be included in the error message if validation fails. |
TypeId | When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute) |
Equals | Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetErrorMessage |
Gets the error message to display if validation failed.
(Overrides ArgumentValidationAttributeGetErrorMessage(CommandLineArgument, Object)) |
GetHashCode | Returns the hash code for this instance. (Inherited from Attribute) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
GetUsageHelp |
Gets the usage help message for this validator.
(Inherited from ArgumentValidationWithHelpAttribute) |
GetUsageHelpCore |
Gets the usage help message for this validator.
(Overrides ArgumentValidationWithHelpAttributeGetUsageHelpCore(CommandLineArgument)) |
IsDefaultAttribute | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute) |
IsValidPostConversion | Determines if the argument's value is defined. (Overrides ArgumentValidationAttributeIsValidPostConversion(CommandLineArgument, Object)) |
IsValidPostParsing |
Determines if the argument's value is valid after all arguments have been parsed.
(Inherited from ArgumentValidationAttribute) |
IsValidPreConversion | Determines if the argument's value contains commas or numbers if not allowed. (Overrides ArgumentValidationAttributeIsValidPreConversion(CommandLineArgument, ReadOnlyMemoryChar)) |
Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute) |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
ToString | Returns a string that represents the current object. (Inherited from Object) |
ValidatePostConversion |
Validates the argument value after it was converted to the argument's type, and throws an
exception if validation failed.
(Inherited from ArgumentValidationAttribute) |
ValidatePostParsing |
Validates the argument value after it was converted to the argument's type, and throws an
exception if validation failed.
(Inherited from ArgumentValidationAttribute) |
ValidatePreConversion |
Validates the argument raw argument value, and throws an exception if validation failed.
(Inherited from ArgumentValidationAttribute) |