TupleComparerBase
Base class for comparators for tuples (both regular Tuples and ValueTuples).
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints.Comparers
{
internal static class TupleComparerBase
{
[System.Runtime.CompilerServices.NullableContext(1)]
public static EqualMethodResult Equal(object x, object y, ref Tolerance tolerance, ComparisonState state, NUnitEqualityComparer equalityComparer, Func<Type, bool> isCorrectType, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
1,
1,
2
})] Func<Type, string, object, object> getValue)
{
Type type = x.GetType();
Type type2 = y.GetType();
if (!isCorrectType(type) || !isCorrectType(type2))
return EqualMethodResult.TypesNotSupported;
int num = type.GetGenericArguments().Length;
if (num != type2.GetGenericArguments().Length)
return EqualMethodResult.ComparedNotEqual;
ComparisonState state2 = state.PushComparison(x, y);
uint num2 = 0;
int num3;
for (int i = 0; i < num; i++) {
object obj;
if (i >= 7)
obj = "Rest";
else {
num3 = i + 1;
obj = "Item" + num3.ToString();
}
string arg = (string)obj;
object x2 = getValue(type, arg, x);
object y2 = getValue(type2, arg, y);
EqualMethodResult equalMethodResult = equalityComparer.AreEqual(x2, y2, ref tolerance, state2);
switch (equalMethodResult) {
case EqualMethodResult.ComparedNotEqual:
return equalMethodResult;
case EqualMethodResult.ToleranceNotSupported:
num2 = (uint)((int)num2 | (1 << i));
break;
}
}
if (num2 == (uint)((1 << num) - 1))
return EqualMethodResult.ToleranceNotSupported;
if (num2 != 0) {
Tolerance tolerance2 = Tolerance.Exact;
for (int j = 0; j < num; j++) {
if (((int)num2 & (1 << j)) != 0) {
object obj2;
if (j >= 7)
obj2 = "Rest";
else {
num3 = j + 1;
obj2 = "Item" + num3.ToString();
}
string arg2 = (string)obj2;
object x3 = getValue(type, arg2, x);
object y3 = getValue(type2, arg2, y);
EqualMethodResult equalMethodResult2 = equalityComparer.AreEqual(x3, y3, ref tolerance2, state2);
if (equalMethodResult2 == EqualMethodResult.ComparedNotEqual)
return equalMethodResult2;
}
}
}
return EqualMethodResult.ComparedEqual;
}
}
}