Class CompareToAttribute
- Namespace
- Acuit.Pinpoint.Common.Validation
- Assembly
- Acuit.Pinpoint.Common.dll
Used for specifying a compare-to validation constraint.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter, AllowMultiple = false)]
public abstract class CompareToAttribute : ValidationAttribute, _Attribute
- Inheritance
-
CompareToAttribute
- Implements
- Derived
- Inherited Members
Constructors
CompareToAttribute(Type, object, bool, bool, bool)
Initializes a new instance of the CompareToAttribute class.
protected CompareToAttribute(Type operandType, object comparisonValue, bool allowLessThan, bool allowEqualTo, bool allowGreaterThan)
Parameters
operandType
TypeThe type of the range parameters. Must implement IComparable.
comparisonValue
objectThe comparison value.
allowLessThan
boolWhether to allow values less than
comparisonValue
.allowEqualTo
boolWhether to allow values equal to
comparisonValue
.allowGreaterThan
boolWhether to allow values greater than
comparisonValue
.
CompareToAttribute(Type, object, bool, bool, bool, Func<string>)
Initializes a new instance of the CompareToAttribute class.
protected CompareToAttribute(Type operandType, object comparisonValue, bool allowLessThan, bool allowEqualTo, bool allowGreaterThan, Func<string> errorMessageAccessor)
Parameters
operandType
TypeThe type of the range parameters. Must implement IComparable.
comparisonValue
objectThe comparison value.
allowLessThan
boolWhether to allow values less than
comparisonValue
.allowEqualTo
boolWhether to allow values equal to
comparisonValue
.allowGreaterThan
boolWhether to allow values greater than
comparisonValue
.errorMessageAccessor
Func<string>The Func<TResult> that will return an error message.
CompareToAttribute(Type, object, bool, bool, bool, string)
Initializes a new instance of the CompareToAttribute class.
protected CompareToAttribute(Type operandType, object comparisonValue, bool allowLessThan, bool allowEqualTo, bool allowGreaterThan, string errorMessage)
Parameters
operandType
TypeThe type of the range parameters. Must implement IComparable.
comparisonValue
objectThe comparison value.
allowLessThan
boolWhether to allow values less than
comparisonValue
.allowEqualTo
boolWhether to allow values equal to
comparisonValue
.allowGreaterThan
boolWhether to allow values greater than
comparisonValue
.errorMessage
stringA non-localized error message to use.
Properties
AllowEqualTo
Gets whether equal-to comparisons are considered valid.
public bool AllowEqualTo { get; }
Property Value
AllowGreaterThan
Gets whether greater-than comparisons are considered valid.
public bool AllowGreaterThan { get; }
Property Value
AllowLessThan
Gets whether less-than comparisons are considered valid.
public bool AllowLessThan { get; }
Property Value
ComparisonValue
Gets the value for comparison.
public object ComparisonValue { get; }
Property Value
OperandType
Gets the type of the ComparisonValue value (e.g. int, double, or some custom type).
public Type OperandType { get; }
Property Value
Methods
FormatErrorMessage(string)
Applies formatting to an error message, based on the data field where the error occurred.
public override string FormatErrorMessage(string name)
Parameters
name
stringThe name to include in the formatted message.
Returns
- string
An instance of the formatted error message.
IsValid(object)
Checks whether the specified object is valid.
public override bool IsValid(object value)
Parameters
value
objectThe value of the object to validate.