private void EndObserveDependency(Dependency dependency) { if (dependency.Target == null) return; dependency.Target.PropertyChanged -= dependency.Handler; dependency.SubDependencies.ForEach(this.EndObserveDependency); }
private void BeginObserveDependency(Dependency dependency) { dependency.UpdateTarget(); Require.NotNull<BindingException>(dependency.Target, dependency.PropertyName); dependency.Handler = this.OnDependencyValueChanged(dependency); dependency.Target.PropertyChanged += dependency.Handler; dependency.SubDependencies.ForEach(this.BeginObserveDependency); }
public DependencyWatcher( Dependency[] dependencies, BindingMode mode, BindindErrorOptions errorOptions ) { _dependencies = dependencies; _mode = mode; _errorOptions = errorOptions; }
private PropertyChangedEventHandler OnDependencyValueChanged(Dependency dependency) { return (sender, args) => { if (dependency.PropertyName != args.PropertyName) return; this.Protect(() => { this.UpdateHandlers(dependency); this.ValueChanged(this, EventArgs.Empty); }); }; }
protected override Expression VisitMember(MemberExpression node) { if (!(node.Member is PropertyInfo)) return base.VisitMember(node); if (!node.Expression.Type.Implements<INotifyPropertyChanged>()) return base.VisitMember(node); var dependency = new Dependency(node.Expression, node.Member.Name); dependency.SubDependencies.AddRange(_dependencies); _dependencies = new[] { dependency }; return base.VisitMember(node); }
private IDisposable PushChildDependencies(Dependency dependency) { _childDependencies.Push(dependency); return Disposable.Create(() => _childDependencies.Pop()); }
private Dependency AddDependency(Expression expression, string propertyName) { var dependency = new Dependency(expression, propertyName); dependency.SubDependencies.AddRange(this._childDependencies); _dependencies.Add(dependency); return dependency; }
private void UpdateHandlers(Dependency dependency) { dependency.SubDependencies.ForEach(this.EndObserveDependency); dependency.SubDependencies.ForEach(this.BeginObserveDependency); }