// ReSharper disable once UnusedParameter.Local private static bool MemberValueEquals( object x, object y, MemberInfo propertyInfo, MemberSettings settings, ReferencePairCollection referencePairs) { bool result; if (TryGetValueEquals(x, y, settings, out result)) { return(result); } switch (settings.ReferenceHandling) { case ReferenceHandling.References: return(ReferenceEquals(x, y)); case ReferenceHandling.Structural: Verify.CanEqualByMemberValues(x, y, settings); return(MemberValues(x, y, settings, referencePairs)); case ReferenceHandling.Throw: throw Throw.ShouldNeverGetHereException(); default: throw new ArgumentOutOfRangeException( nameof(settings.ReferenceHandling), settings.ReferenceHandling, null); } }
internal static bool MemberValues <T>(T x, T y, MemberSettings settings) { if (TryGetValueEquals(x, y, settings, out var result)) { return(result); } Verify.CanEqualByMemberValues(x, y, settings, typeof(EqualBy).Name, settings.EqualByMethodName()); using (var borrowed = settings.ReferenceHandling == ReferenceHandling.Structural ? ReferencePairCollection.Borrow() : null) { return(MemberValues(x, y, settings, borrowed?.Value)); } }
/// <summary> /// Check if the fields of <paramref name="type"/> can be compared for equality /// This method will throw an exception if copy cannot be performed for <paramref name="type"/> /// Read the exception message for detailed instructions about what is wrong. /// Use this to fail fast or in unit tests. /// </summary> /// <param name="type">The type to check.</param> /// <param name="settings">The settings to use.</param> public static void VerifyCanEqualByFieldValues(Type type, FieldsSettings settings) { Verify.CanEqualByMemberValues(type, settings, typeof(EqualBy).Name, nameof(EqualBy.FieldValues)); }
/// <summary> /// Check if the properties of <paramref name="type"/> can be compared for equality /// This method will throw an exception if copy cannot be performed for <paramref name="type"/> /// Read the exception message for detailed instructions about what is wrong. /// Use this to fail fast or in unit tests. /// </summary> /// <param name="type">The type to check.</param> /// <param name="settings">The settings to use.</param> public static void VerifyCanEqualByPropertyValues(Type type, PropertiesSettings settings) { Verify.CanEqualByMemberValues(type, settings, typeof(EqualBy).Name, nameof(EqualBy.PropertyValues)); }