Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        internal static void Sync <T>(T source, T target, MemberSettings settings, ReferencePairCollection referencePairs)
        {
            Debug.Assert(source != null, nameof(source));
            Debug.Assert(target != null, nameof(target));
            Debug.Assert(source.GetType() == target.GetType(), "Must be same type");
            Verify.CanCopyMemberValues(source, target, settings);

            if (referencePairs?.Add(source, target) == false)
            {
                return;
            }

            if (TryCustomCopy(source, target, settings, out var copy))
            {
                return;
            }

            CollectionItems(source, target, settings, referencePairs);
            Members(source, target, settings, referencePairs);
        }