<PackageReference Include="NUnit" Version="4.3.2" />

KeyValuePairsComparer

static class KeyValuePairsComparer
Comparator for two KeyValuePair<T, U>s.
using System; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace NUnit.Framework.Constraints.Comparers { internal static class KeyValuePairsComparer { [NullableContext(1)] public static EqualMethodResult Equal(object x, object y, ref Tolerance tolerance, ComparisonState state, NUnitEqualityComparer equalityComparer) { Type type = x.GetType(); Type type2 = y.GetType(); Type left = type.IsGenericType ? type.GetGenericTypeDefinition() : null; Type left2 = type2.IsGenericType ? type2.GetGenericTypeDefinition() : null; if (left != typeof(KeyValuePair<, >) || left2 != typeof(KeyValuePair<, >)) return EqualMethodResult.TypesNotSupported; ComparisonState state2 = state.PushComparison(x, y); Tolerance tolerance2 = Tolerance.Exact; object value = type.GetProperty("Key").GetValue(x, null); object value2 = type2.GetProperty("Key").GetValue(y, null); EqualMethodResult equalMethodResult = equalityComparer.AreEqual(value, value2, ref tolerance2, state2); if (equalMethodResult == EqualMethodResult.ComparedEqual) { object value3 = type.GetProperty("Value").GetValue(x, null); object value4 = type2.GetProperty("Value").GetValue(y, null); equalMethodResult = equalityComparer.AreEqual(value3, value4, ref tolerance, state2); } return equalMethodResult; } } }