public ObservableCollectionSnapshot(DirtyModelDetector modelDetector, INotifyCollectionChanged iCollectionAsINotifyCollectionChanged, IEnumerable listenedCollectionAsIEnumerable) : base(modelDetector, iCollectionAsINotifyCollectionChanged) { if (iCollectionAsINotifyCollectionChanged == null) { throw new ArgumentNullException("iCollectionAsINotifyCollectionChanged"); } if (listenedCollectionAsIEnumerable == null) { throw new ArgumentNullException("listenedCollectionAsIEnumerable"); } if (!ReferenceEquals(iCollectionAsINotifyCollectionChanged, listenedCollectionAsIEnumerable)) { throw new Exception("Same instance expected"); } _listenedCollectionAsINotifyCollectionChanged = iCollectionAsINotifyCollectionChanged; _listenedCollectionAsIEnumerable = listenedCollectionAsIEnumerable; var itemsSnapshot = new List <SnapshotElement>(); foreach (var item in _listenedCollectionAsIEnumerable) { itemsSnapshot.Add(SnaphotFactory.Create(modelDetector, item)); } _itemsSnapshot = new ReadOnlyCollection <SnapshotElement>(itemsSnapshot); _listenedCollectionAsINotifyCollectionChanged.CollectionChanged += OnCollectionChanged; }
public NotifyPropertyChangedSnapshot(DirtyModelDetector modelDetector, INotifyPropertyChanged snapshotValue) : base(modelDetector, snapshotValue) { if (snapshotValue == null) { throw new ArgumentNullException("snapshotValue"); } foreach (var propertyInfo in snapshotValue.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { var getMethod = propertyInfo.GetGetMethod(); if (getMethod != null && getMethod.GetParameters().Any()) { continue; } var attributes = propertyInfo.GetCustomAttributes(typeof(IsSerialized), true); if (attributes.Length <= 0) { continue; } var snapshot = SnaphotFactory.Create(modelDetector, propertyInfo.GetValue(snapshotValue, null)); var keyValuePair = new KeyValuePair <PropertyInfo, SnapshotElement>(propertyInfo, snapshot); _propertiesSnapshots.Add(propertyInfo.Name, keyValuePair); } _listenedNotifyPropertyChanged = snapshotValue; _listenedNotifyPropertyChanged.PropertyChanged += OnPropertyChanged; }
public NotifyPropertyChangedSnapshot(DirtyModelDetector modelDetector, INotifyPropertyChanged snapshotValue) : base(modelDetector, snapshotValue) { if (snapshotValue == null) { throw new ArgumentNullException("snapshotValue"); } foreach (var propertyInfo in snapshotValue.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { var getMethod = propertyInfo.GetGetMethod(); if (getMethod != null && getMethod.GetParameters().Any()) { continue; } var attributes = propertyInfo.GetCustomAttributes(typeof(IsSerialized), true); if (attributes.Length <= 0) { continue; } var snapshot = SnaphotFactory.Create(modelDetector, propertyInfo.GetValue(snapshotValue, null)); var keyValuePair = new KeyValuePair<PropertyInfo, SnapshotElement>(propertyInfo, snapshot); _propertiesSnapshots.Add(propertyInfo.Name, keyValuePair); } _listenedNotifyPropertyChanged = snapshotValue; _listenedNotifyPropertyChanged.PropertyChanged += OnPropertyChanged; }
internal SnapshotElement(DirtyModelDetector modelDetector, object snapshotValue) { if (modelDetector == null) { throw new ArgumentNullException("modelDetector"); } _modelDetector = modelDetector; _snapshotValue = snapshotValue; }
/// <summary> /// Create <see cref="SnapshotElement"/> according to given objet type /// </summary> /// <param name="dirtyModelDetector"></param> /// <param name="value"></param> /// <returns></returns> public static SnapshotElement Create(DirtyModelDetector dirtyModelDetector, object value) { var valueAsINotifyCollectionChanged = value as INotifyCollectionChanged; var valueAsIEnumerable = value as IEnumerable; if (valueAsINotifyCollectionChanged != null && valueAsIEnumerable != null) { return(new ObservableCollectionSnapshot(dirtyModelDetector, valueAsINotifyCollectionChanged, valueAsIEnumerable)); } else { var valueAsINotifyPropertyChanged = value as INotifyPropertyChanged; if (valueAsINotifyPropertyChanged != null) { return(new NotifyPropertyChangedSnapshot(dirtyModelDetector, valueAsINotifyPropertyChanged)); } else { return(new EqualsComparatorSnapshot(dirtyModelDetector, value)); } } }
public ObservableCollectionSnapshot(DirtyModelDetector modelDetector, INotifyCollectionChanged iCollectionAsINotifyCollectionChanged, IEnumerable listenedCollectionAsIEnumerable) : base(modelDetector, iCollectionAsINotifyCollectionChanged) { if (iCollectionAsINotifyCollectionChanged == null) throw new ArgumentNullException("iCollectionAsINotifyCollectionChanged"); if (listenedCollectionAsIEnumerable == null) throw new ArgumentNullException("listenedCollectionAsIEnumerable"); if (!ReferenceEquals(iCollectionAsINotifyCollectionChanged, listenedCollectionAsIEnumerable)) throw new Exception("Same instance expected"); _listenedCollectionAsINotifyCollectionChanged = iCollectionAsINotifyCollectionChanged; _listenedCollectionAsIEnumerable = listenedCollectionAsIEnumerable; var itemsSnapshot = new List<SnapshotElement>(); foreach (var item in _listenedCollectionAsIEnumerable) { itemsSnapshot.Add(SnaphotFactory.Create(modelDetector, item)); } _itemsSnapshot = new ReadOnlyCollection<SnapshotElement>(itemsSnapshot); _listenedCollectionAsINotifyCollectionChanged.CollectionChanged += OnCollectionChanged; }
/// <summary> /// Create <see cref="SnapshotElement"/> according to given objet type /// </summary> /// <param name="dirtyModelDetector"></param> /// <param name="value"></param> /// <returns></returns> public static SnapshotElement Create(DirtyModelDetector dirtyModelDetector, object value) { var valueAsINotifyCollectionChanged = value as INotifyCollectionChanged; var valueAsIEnumerable = value as IEnumerable; if (valueAsINotifyCollectionChanged != null && valueAsIEnumerable != null) { return new ObservableCollectionSnapshot(dirtyModelDetector, valueAsINotifyCollectionChanged, valueAsIEnumerable); } else { var valueAsINotifyPropertyChanged = value as INotifyPropertyChanged; if (valueAsINotifyPropertyChanged != null) { return new NotifyPropertyChangedSnapshot(dirtyModelDetector, valueAsINotifyPropertyChanged); } else { return new EqualsComparatorSnapshot(dirtyModelDetector, value); } } }
public void SetUp() { _modelDirtyDetector = new DirtyModelDetector(); _testingClassA = CreateNewClassA(); }
public EqualsComparatorSnapshot(DirtyModelDetector modelDetector, object snapshotValue) : base(modelDetector, snapshotValue) { }