Feature | Is supported |
---|---|
Null safe | |
Validation | |
EF Core | |
EF 6 | |
External Comparer |
Validation result
Error
"Object is greater than [{LessThan}]".
"Object is lower than or equal to [{LessThan}]" - for negation.
Parameters
Parameter | Description |
---|---|
LessThan | Limit passed in constructor. |
Info
Checks if candidate object is lower than or equal to expected value.
Specification for comparison use (in order):
IComparer<T>
- if available.- <= operator - if defined for T.
CompareTo()
method - if T implementsIComparable<T>
.CompareTo(Object)
method - if T implementsIComparable
.
Note that, null
is always the lowest value.
Usage
var spec = Specification.LessThanOrEqual<double?>(1.45);
spec.IsSatisfiedBy(1.43); // true
spec.IsSatisfiedBy(5.0); // false
spec.IsSatisfiedBy(null); // true
As property
var customerSpec = Specification.LessThanOrEqual<Customer, int>(
c => c.CustomerId, 100);
customerSpec.IsSatisfiedBy(new Customer { CustomerId = 1 }); // true
customerSpec.IsSatisfiedBy(new Customer { CustomerId = 100 }); // true
Not Less Than Or Equal
var spec = Specification.NotLessThanOrEqual<double?>(1.45);
spec.IsSatisfiedBy(1.43); // false
spec.IsSatisfiedBy(5.0); // true
spec.IsSatisfiedBy(null); // false
As property
var customerSpec = Specification.NotLessThanOrEqual<Customer, int>(
c => c.CustomerId, 100);
customerSpec.IsSatisfiedBy(new Customer { CustomerId = 1 }); // false
customerSpec.IsSatisfiedBy(new Customer { CustomerId = 100 }); // true
Comparer
LessThanOrEqualSpecification<T>
supports IComparer<T>
.
var spec = Specification.LessThanOrEqual<double>(
0.0045, Comparer<double>.Default);
EF 6 support
LessThanOrEqualSpecification<T>
works correctly in EF 6 solution, when T is primitive or enum type.
Non primitive types, may generate NotSupportedException
.