Example #1
0
        private static ValueDiff TryCreateValueDiff <T>(T x, T y, MemberSettings settings)
        {
            Debug.Assert(x != null, "x == null");
            Debug.Assert(y != null, "y == null");
            Debug.Assert(settings != null, "settings == null");

            if (TryGetValueDiff(x, y, settings, out var diff))
            {
                return(diff);
            }

            using (var borrow = DiffBuilder.GetOrCreate(x, y, settings))
            {
                borrow.Value.UpdateDiffs(x, y, settings);
                return(borrow.Value.CreateValueDiffOrNull());
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DirtyTrackerNode"/> class.
        /// A call to Initialize is needed after the ctor due to that we need to fetch child nodes and the graph can contain self
        /// </summary>
        private DirtyTrackerNode(IRefCounted <ReferencePair> refCountedPair, PropertiesSettings settings, bool isRoot)
        {
            this.refCountedPair = refCountedPair;
            var x = refCountedPair.Value.X;
            var y = refCountedPair.Value.Y;

            this.children = ChildNodes <DirtyTrackerNode> .Borrow();

            this.xNode = RootChanges.GetOrCreate(x, settings, isRoot);
            this.yNode = RootChanges.GetOrCreate(y, settings, isRoot);
            this.xNode.Value.PropertyChange += this.OnTrackedPropertyChange;
            this.yNode.Value.PropertyChange += this.OnTrackedPropertyChange;

            this.IsTrackingCollectionItems = Is.Enumerable(x, y) &&
                                             !settings.IsImmutable(x.GetType().GetItemType()) &&
                                             !settings.IsImmutable(y.GetType().GetItemType());

            if (Is.NotifyingCollections(x, y))
            {
                this.xNode.Value.Add     += this.OnTrackedAdd;
                this.xNode.Value.Remove  += this.OnTrackedRemove;
                this.xNode.Value.Replace += this.OnTrackedReplace;
                this.xNode.Value.Move    += this.OnTrackedMove;
                this.xNode.Value.Reset   += this.OnTrackedReset;

                this.yNode.Value.Add     += this.OnTrackedAdd;
                this.yNode.Value.Remove  += this.OnTrackedRemove;
                this.yNode.Value.Replace += this.OnTrackedReplace;
                this.yNode.Value.Move    += this.OnTrackedMove;
                this.yNode.Value.Reset   += this.OnTrackedReset;
            }

            var builder = DiffBuilder.GetOrCreate(x, y, settings);

            builder.Value.UpdateDiffs(x, y, settings);
            builder.Value.Refresh();
            this.refcountedDiffBuilder = builder;
            this.isDirty = !this.Builder.IsEmpty;
        }