Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

Created Issue: EqualValidator and NotEqualValidator fail if property/value don't implement IComparable [7130]

$
0
0
New
Hi, in the latest (unstable) check in, usage of the new Internal.Comparer fails in these validators if they've been used for object type properties that don't implement IComparable. Suggest the Compare method of each is changed to fall back to default equality comparison when this occurs:

```
protected bool Compare(object comparisonValue, object propertyValue)
{
if (comparer != null)
{
return comparer.Equals(comparisonValue, propertyValue);
}

if (comparisonValue is IComparable && propertyValue is IComparable)
{
return Internal.Comparer.GetEqualsResult((IComparable)comparisonValue, (IComparable)propertyValue);
}

return comparisonValue == propertyValue;
}
```

Or you could use Object.ReferenceEquals and/or use reflection(?) to find the generic EqualityComparer<T>.Default for the property being examined.

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>