//=============================================================== internal void AddChangeTracker(T obj) { if (!IgnoreChangeTracking && !ChangeTracker <T> .CanTrackChanges) { throw new Exception(String.Format("Cannot enable change tracking for type {0}. Please ensure that it has a public default (parameterless) constructor.", typeof(T))); } UnsavedObjects.Add(new ChangeTracker <T>(obj, KeySelector)); }
//=============================================================== private void ApplyChanges() { // For any modified objects, add an update to the list of pending ops foreach (var obj in UnsavedObjects.Where(x => x.HasChanges)) { Update(obj.CurrentValue, KeySelector(obj.CurrentValue)); } // Run all the pending ops in order foreach (var change in PendingOperations) { change.Apply(); } // Remove all pending changes and unsaved objects, since they're all processed UnsavedObjects.Clear(); PendingOperations.Clear(); }