EqualsComparer
Comparator for a type that overrides Equals
using NUnit.Framework.Internal;
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints.Comparers
{
internal static class EqualsComparer
{
[System.Runtime.CompilerServices.NullableContext(1)]
public static EqualMethodResult Equal(object x, object y, ref Tolerance tolerance, ComparisonState state, NUnitEqualityComparer equalityComparer)
{
if (equalityComparer.CompareAsCollection && state.TopLevelComparison)
return EqualMethodResult.TypesNotSupported;
Type type = x.GetType();
Type type2 = y.GetType();
if (equalityComparer.CompareProperties && (type.HasCompilerGeneratedEquals() || type2.HasCompilerGeneratedEquals()))
return EqualMethodResult.TypesNotSupported;
bool flag = TypeHelper.OverridesEqualsObject(type);
bool flag2 = TypeHelper.OverridesEqualsObject(type2);
if (flag | flag2) {
if (tolerance.HasVariance)
return EqualMethodResult.ToleranceNotSupported;
if (!((flag & flag2) ? (x.Equals(y) || y.Equals(x)) : ((!flag) ? y.Equals(x) : x.Equals(y))))
return EqualMethodResult.ComparedNotEqual;
return EqualMethodResult.ComparedEqual;
}
return EqualMethodResult.TypesNotSupported;
}
}
}