/// <summary> /// Begins observing the given notifying object. /// </summary> /// <param name="notifyingObject"></param> /// <param name="addEventAction"></param> /// <param name="removeEventAction"></param> public void Observe( Object notifyingObject, Action <PropertyChangedEventHandler> addEventAction, Action <PropertyChangedEventHandler> removeEventAction) { notifyingObject.ThrowIfNull("notifyingObject"); addEventAction.ThrowIfNull("addEventAction"); removeEventAction.ThrowIfNull("removeEventAction"); if (IsDisposed) { return; } if (myObservedObjects.ContainsKey(notifyingObject)) { return; } myObservedObjects[notifyingObject] = () => removeEventAction(myPropertyChangedEventHandler); NotificationChainPropertyAttribute.CallProperties(notifyingObject); addEventAction(myPropertyChangedEventHandler); }
/// <summary> /// Begins observing the given notifying collection. /// </summary> /// <param name="notifyingCollection"></param> public void ObserveCollection(INotifyCollectionChanged notifyingCollection) { notifyingCollection.ThrowIfNull("notifyingCollection"); if (IsDisposed) { return; } if (myObservedCollections.ContainsKey(notifyingCollection)) { return; } myObservedCollections[notifyingCollection] = () => notifyingCollection.CollectionChanged -= myCollectionChangedEventHandler; NotificationChainPropertyAttribute.CallProperties(notifyingCollection); notifyingCollection.CollectionChanged += myCollectionChangedEventHandler; var enumerable = notifyingCollection as IEnumerable; if (enumerable != null) { foreach (var item in enumerable) { var inpc = item as INotifyPropertyChanged; if (inpc != null) { base.Observe(inpc); } } } }