/// <summary> /// Initializes a new instance of the <see cref="ObjectObserverRegistration"/> class. /// </summary> /// <param name="observer">The observer.</param> /// <exception cref="System.ArgumentNullException">observer cannot be null</exception> public ObjectObserverRegistration(PropertyPathObserver observer) { if (observer == null) throw new ArgumentNullException("observer"); this.observer = observer; this.observer.PropertyPathChanged += Observer_PropertyPathChanged; this.Actions = new List<PropertyPathChangedAction>(); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyPathObserver"/> class. /// </summary> /// <param name="obj">The object to monitor.</param> /// <param name="propertyPathStack">The property path stack, this stack will be consume /// after this function completes.</param> /// <param name="parent">The parent of this path if any, null if this is the root.</param> /// <exception cref="System.ArgumentNullException">propertyPathStack cannot be null</exception> /// <exception cref="System.ArgumentException"> /// propertyPathStack must have at least one item /// or /// path contains a non property member /// </exception> private void Initialize(INotifyPropertyChanged obj, Stack<MemberExpression> propertyPathStack, PropertyPathObserver parent) { if (propertyPathStack == null) throw new ArgumentNullException("propertyPathStack"); if (propertyPathStack.Count == 0) throw new ArgumentException("propertyPathStack must have at least one item"); var path = propertyPathStack.Pop(); if (!(path.Member is PropertyInfo)) throw new ArgumentException("path contains a non property member"); this.propertyInfo = (PropertyInfo)path.Member; this.ObservableObject = obj; this.Parent = parent; if (propertyPathStack.Count > 0) { this.Child = new PropertyPathObserver(); this.Child.Initialize(this.PropertyValue as INotifyPropertyChanged, propertyPathStack, this); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { this.observer.PropertyPathChanged -= Observer_PropertyPathChanged; this.observer.Dispose(); this.observer = null; }