예제 #1
0
        public void NotifyValueWillBeRemoved <T>(ITrackableCollection <T> trackableCollection, T removed)
        {
            AssertNotLocked();

            if (!_isEnabled)
            {
                return;
            }

            var list = trackableCollection as IList <T>;

            if (list != null)
            {
                var index = list.IndexOf(removed);

                if (index == -1)
                {
                    return;
                }

                _changeHistory.Push(() => trackableCollection.InsertWithoutTracking(removed, index));

                return;
            }

            if (trackableCollection.Contains(removed))
            {
                _changeHistory.Push(() => trackableCollection.AddWithoutTracking(removed));
            }
        }
예제 #2
0
        public void NotifyCollectionWillBeCleared <T>(ITrackableCollection <T> trackableCollection)
        {
            AssertNotLocked();

            if (!_isEnabled)
            {
                return;
            }

            var elements = trackableCollection.ToList();

            if (elements.Count == 0)
            {
                return;
            }

            _changeHistory.Push(() =>
            {
                foreach (var element in elements)
                {
                    trackableCollection.AddWithoutTracking(element);
                }
            });
        }