This project has moved and is read-only. For the latest updates, please go here.

EqualValidator and NotEqualValidator fail if property/value don't implement IComparable


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.


JeremyS wrote Mar 18, 2013 at 11:02 AM

Implemented in latest commit