private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, MulticastPropertyValue propertyValue) { var originalValue = (IList)typeof(ObservableList <>).MakeGenericType(propertyValue.Value.GetType().GetGenericArguments()[0]) .GetConstructor(Type.EmptyTypes).Invoke(null); if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (var removed in e.OldItems) { originalValue.Add(removed); } } foreach (var item in (IEnumerable)propertyValue.Value) { if (((e.Action == NotifyCollectionChangedAction.Remove) && (e.OldItems.Contains(item))) || (e.Action == NotifyCollectionChangedAction.Add)) { continue; } originalValue.Add(item); } OriginalValues.Remove(propertyValue); OriginalValues.Add(new MulticastPropertyValue(propertyValue.CastedType, propertyValue.Property, originalValue)); ((IObservableCollection)sender).ClearCollectionChanged(); }
// Captures the original value for a property that is changing. internal void RecordOriginalValue(string propertyName, object oldValue, object newValue) { if (IsChangeTrackingEnabled && _objectState != ObjectState.Added) { if (OriginalValues.ContainsKey(propertyName)) { if (object.Equals(OriginalValues[propertyName], newValue)) { OriginalValues.Remove(propertyName); if (OriginalValues.Count == 0 && _objectState == ObjectState.Modified) { State = ObjectState.Unchanged; ModifiedProperties.Clear(); } else { ModifiedProperties.Remove(propertyName); } } } else { OriginalValues[propertyName] = oldValue; } } }
// Captures the original value for a property that is changing. internal void RecordValue(string propertyName, object oldValue, object newValue) { if (_changeTrackingEnabled && _objectState != ObjectState.Added) { if (OriginalValues.ContainsKey(propertyName) && OriginalValues[propertyName] == newValue) { // On repasse à l'état initial OriginalValues.Remove(propertyName); ModifiedValues.Remove(propertyName); } else { if (!OriginalValues.ContainsKey(propertyName)) { OriginalValues[propertyName] = oldValue; } ModifiedValues[propertyName] = newValue; } } }