private void Subscribe() { INotifyPropertyChanged subject = this.Subject; if (subject == null) { return; } for (int i = 0; i < this.AccessNode.Children.Count; i++) { PropertyAccessNode propertyNode = (PropertyAccessNode)this.AccessNode.Children[i]; WeakPropertyChangedEventManager.Register( subject, propertyNode.Property.Name, this, (me, sender, args) => me.OnPropertyChanged(sender, args)); } if (this.Children != null) { for (int i = 0; i < this.Children.Count; i++) { this.Children[i].UpdateSubject(subject); } } }
private void RegisterOnPersonName() { WeakPropertyChangedEventManager.Register( _person, "Name", _listener, (me, sender, args) => me.OnPropertyChanged(sender, args)); }
public void Unsubscribe( INotifyPropertyChanged subject, object rootSubject, TListener listener) { WeakPropertyChangedEventManager.Unregister(subject, _propertyAccessNode.PropertyName, listener, rootSubject); UnsubscribeFromChildren(listener, subject, rootSubject); }
public void Unregister_MonitoredPropertyChanged_DoesNotFireCallback() { RegisterOnPersonName(); WeakPropertyChangedEventManager.Unregister(_person, "Name", _listener, null); _person.Name = "Bob"; Assert.AreEqual(0, _listener.CallCount); }
public void Subscribe(INotifyPropertyChanged subject, object rootSubject, TListener listener) { WeakPropertyChangedEventManager.Register( subject, rootSubject, _propertyAccessNode.PropertyName, listener, _onChangingCallback, _onChangedCallback); SubscribeToChildren(listener, subject, rootSubject); }
public void Test() { // Collection with 1 item to make this test simple Items = new ContinuousCollection <NotifiableItem> { new NotifiableItem { TestValue1 = 3, TestValue2 = 10 }, }; // Start with TestValue1 MaxValueCV = Items.ContinuousMax(item => item.TestValue1, value => Max = value); Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue); Console.WriteLine("Max = " + Max); Console.WriteLine(); // Switch to TestValue2 MaxValueCV = Items.ContinuousMax(item => item.TestValue2, value => Max = value); Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue); Console.WriteLine("Max = " + Max); Console.WriteLine(); GC.Collect(); WeakPropertyChangedEventManager.RemoveCollectedEntries(); GC.Collect(); // Now set TestValue1 Items[0].TestValue1 = 20; Console.WriteLine("(BUG)"); Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue); // BUG: Max is set to 20 when it should be 10 Console.WriteLine("Max = " + Max); Assert.AreEqual(10, Max); Console.Write("Hit enter to continue..."); Console.ReadLine(); }
private void Unsubscribe() { INotifyPropertyChanged subject = this.Subject; if (subject == null) { return; } for (int i = 0; i < this.AccessNode.Children.Count; i++) { PropertyAccessNode propertyNode = (PropertyAccessNode)this.AccessNode.Children[i]; WeakPropertyChangedEventManager.Unregister(subject, propertyNode.Property.Name, this, null); } if (this.Children != null) { for (int i = 0; i < this.Children.Count; i++) { this.Children[i].Unsubscribe(); } } }
public void CleanupReferences() { RegisterOnPersonName(); WeakReference personRef = new WeakReference(_person); _person = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Assert.IsFalse(personRef.IsAlive); WeakPropertyChangedEventManager.RemoveCollectedEntries(); for (int i = 0; i < 10; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); WeakPropertyChangedEventManager.RemoveCollectedEntries(); } Assert.AreEqual(0, WeakPropertyChangedEventManager.SourceToBridgeTable.Count); }