Class AllowedValuesAttribute
- Namespace
- McMaster.Extensions.CommandLineUtils
- Assembly
- McMaster.Extensions.CommandLineUtils.dll
Specifies a set of allowed values and a comparer used to determine if a value is in that set.
By default, value comparison is case-sensitive. To ensure case matches exactly, set IgnoreCase to false.
[AttributeUsage(AttributeTargets.Property)]
public sealed class AllowedValuesAttribute : ValidationAttribute
- Inheritance
-
objectAttributeValidationAttributeAllowedValuesAttribute
Constructors
AllowedValuesAttribute(StringComparison, params string[])
Initializes an instance of AllowedValuesAttribute.
public AllowedValuesAttribute(StringComparison comparer, params string[] allowedValues)
Parameters
comparerStringComparisonallowedValuesstring[]
AllowedValuesAttribute(params string[])
Initializes an instance of AllowedValuesAttribute.
public AllowedValuesAttribute(params string[] allowedValues)
Parameters
allowedValuesstring[]
Properties
Comparer
The comparison method used.
public StringComparison Comparer { get; set; }
Property Value
IgnoreCase
Comparison between values and allowed values should ignore case.
public bool IgnoreCase { get; set; }
Property Value
Methods
IsValid(object?, ValidationContext)
Validates the specified value with respect to the current validation attribute.
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
Parameters
valueobjectThe value to validate.
validationContextValidationContextThe context information about the validation operation.
Returns
- ValidationResult
An instance of the ValidationResult class.
Exceptions
- InvalidOperationException
The current attribute is malformed.
- NotImplementedException
IsValid(object, ValidationContext) has not been implemented by a derived class.