예제 #1
0
        internal static void UpdateCollectionItemDiff(
            this DiffBuilder collectionBuilder,
            object xItem,
            object yItem,
            object index,
            MemberSettings settings)
        {
            ValueDiff diff;

            if (TryGetValueDiff(xItem, yItem, settings, out diff))
            {
                if (diff != null)
                {
                    collectionBuilder.Add(new IndexDiff(index, diff));
                }
                else
                {
                    collectionBuilder.Remove(index);
                }

                return;
            }

            if (settings.ReferenceHandling == ReferenceHandling.References)
            {
                if (ReferenceEquals(xItem, yItem))
                {
                    collectionBuilder.Remove(index);
                }
                else
                {
                    collectionBuilder.Add(new IndexDiff(index, new ValueDiff(xItem, yItem)));
                }

                return;
            }

            IRefCounted <DiffBuilder> subDiffBuilder;

            if (DiffBuilder.TryCreate(xItem, yItem, settings, out subDiffBuilder))
            {
                subDiffBuilder.Value.UpdateDiffs(xItem, yItem, settings);
            }

            collectionBuilder.AddLazy(index, subDiffBuilder.Value);
        }
예제 #2
0
        private static void AddItemDiffs(DiffBuilder collectionBuilder, ISet <T> x, ISet <T> y, HashSet <T> borrow)
        {
            borrow.UnionWith(x);
            if (borrow.SetEquals(y))
            {
                return;
            }

            borrow.ExceptWith(y);
            foreach (var xi in borrow)
            {
                collectionBuilder.Add(new IndexDiff(xi, new ValueDiff(xi, PaddedPairs.MissingItem)));
            }

            borrow.Clear();
            borrow.UnionWith(y);
            borrow.ExceptWith(x);
            foreach (var yi in borrow)
            {
                collectionBuilder.Add(new IndexDiff(yi, new ValueDiff(PaddedPairs.MissingItem, yi)));
            }
        }
예제 #3
0
        private void AddDiffs(
            DiffBuilder collectionBuilder,
            Array x,
            Array y,
            MemberSettings settings)
        {
            if (TryGetRankDiff(x, y, out var rankDiff))
            {
                collectionBuilder.Add(rankDiff);
                return;
            }

            foreach (var index in x.Indices())
            {
                collectionBuilder.UpdateCollectionItemDiff(x.GetValue(index), y.GetValue(index), new Index(index), settings);
            }
        }