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 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; }