Esempio n. 1
0
        internal static bool KeysAndValuesEquals(
            IReadOnlyDictionary <TKey, TValue> x,
            IReadOnlyDictionary <TKey, TValue> y,
            MemberSettings settings,
            ReferencePairCollection referencePairs)
        {
            foreach (var key in x.Keys)
            {
                var xv = x[key];

                TValue yv;
                if (!y.TryGetValue(key, out yv))
                {
                    return(false);
                }

                if (referencePairs?.Contains(xv, yv) == true)
                {
                    continue;
                }

                if (!EqualBy.MemberValues(xv, yv, settings, referencePairs))
                {
                    return(false);
                }
            }

            return(true);
        }
        internal static bool MemberValues <T>(
            T x,
            T y,
            MemberSettings settings,
            ReferencePairCollection referencePairs)
        {
            bool result;

            if (TryGetValueEquals(x, y, settings, out result))
            {
                return(result);
            }

            referencePairs?.Add(x, y);

            if (x is IEnumerable)
            {
                if (!EnumerableEquals(x, y, settings, referencePairs))
                {
                    return(false);
                }
            }

            foreach (var member in settings.GetMembers(x.GetType()))
            {
                if (settings.IsIgnoringMember(member))
                {
                    continue;
                }

                var    getterAndSetter = settings.GetOrCreateGetterAndSetter(member);
                bool   equal;
                object yv;
                object xv;
                if (getterAndSetter.TryGetValueEquals(x, y, settings, out equal, out xv, out yv))
                {
                    if (!equal)
                    {
                        return(false);
                    }

                    continue;
                }

                if (member.MemberType().IsClass&& referencePairs?.Contains(xv, yv) == true)
                {
                    continue;
                }

                if (!MemberValueEquals(xv, yv, member, settings, referencePairs))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        private static bool Equals(
            IList <T> x,
            IList <T> y,
            MemberSettings settings,
            ReferencePairCollection referencePairs)
        {
            for (var i = 0; i < x.Count; i++)
            {
                var xv = x[i];
                var yv = y[i];
                if (referencePairs?.Contains(xv, yv) == true)
                {
                    continue;
                }

                if (!EqualBy.MemberValues(xv, yv, settings, referencePairs))
                {
                    return(false);
                }
            }

            return(true);
        }