public Function(IWeakEvent[] changeTriggers, object target, Func <object, TV> getter) { Contract.AllIsNotNull(changeTriggers, target, getter); _receiver = new EventReceiver(OnTrigger); foreach (var trig in changeTriggers) { trig.AddReceiver(_receiver); } _target = new WeakReference(target, false); _getter = getter; }
public WrapperCollection(WeakObservableCollection <T> src) { _coll = src; _updater = new EventReceiver <NotifyCollectionChangedEventArgs>( coll_CollectionChanged); _propertyUpdater = new EventReceiver <PropertyChangedEventArgs>( coll_PropertyChanged); _coll.ContentChanged.AddReceiver(_updater); _coll.PropertyValueChanged.AddReceiver(_propertyUpdater); }
public AutoConvertCollection(IReadOnlyCollection <T1> source, Func <T1, T2> converter, bool IsDistinct) { Contract.IsNotNull(source); Contract.IsNotNull(converter); _converter = converter; _src = source; _IsDistinct = IsDistinct; ReloadAll(); _adder = new EventReceiver <ObjectEventArgs>((x, y) => this.Add((T1)y.Arg)); _remover = new EventReceiver <ObjectEventArgs>((x, y) => this.Remove((T1)y.Arg)); _reset = new EventReceiver((x, y) => this.ReloadAll()); _src.Added.AddReceiver(_adder); _src.Removed.AddReceiver(_remover); _src.Reset.AddReceiver(_reset); }
public UnionCollection(IReadOnlyCollection <T1> source, Expander <T1, T2> expander) { Contract.IsNotNull(source); Contract.IsNotNull(expander); _expander = expander; _src = source; _addSource = new EventReceiver <ObjectEventArgs>((x, y) => this.OnAdd((T1)y.Arg)); _removeSource = new EventReceiver <ObjectEventArgs>((x, y) => OnRemove((T1)y.Arg)); _resetSource = new EventReceiver((x, y) => ReloadAll()); _addItem = new EventReceiver <ObjectEventArgs>((x, y) => this.OnAddItem((T2)y.Arg)); _removeItem = new EventReceiver <ObjectEventArgs>((x, y) => this.OnRemoveItem((T2)y.Arg)); _resetItems = new EventReceiver((x, y) => ResetSource((IReadOnlyCollection <T2>)x)); _src.Added.AddReceiver(_addSource); _src.Removed.AddReceiver(_removeSource); _src.Reset.AddReceiver(_resetSource); _resetSource.Ping(); }
public void test_WrapperCollection() { NotifyCollectionChangedAction lastAction = NotifyCollectionChangedAction.Reset; object lastAdd = null; object lastRemove = null; int changeCounter = 0; EventReceiver onAdd = new EventReceiver((x, y) => lastAdd = ((ObjectEventArgs)y).Arg), onRemove = new EventReceiver((x, y) => lastRemove = ((ObjectEventArgs)y).Arg), onChange = new EventReceiver((x, y) => ++changeCounter); var targetColl = new WeakObservableCollection<string>(); var wcoll = new WrapperCollection<string>(targetColl); wcoll.Added.AddReceiver(onAdd); wcoll.Removed.AddReceiver(onRemove); wcoll.Changed.AddReceiver(onChange); wcoll.CollectionChanged += (x, y) => { lastAction = y.Action; }; string t1 = "aaa", t2 = "bbb"; CompareWrap(targetColl, wcoll, t1, t2); Assert.AreEqual(0, changeCounter); targetColl.Add(t1); CompareWrap(targetColl, wcoll, t1, t2); Assert.AreEqual(1, changeCounter); Assert.AreEqual(t1, lastAdd); Assert.AreEqual(NotifyCollectionChangedAction.Add, lastAction); targetColl.Add(t2); CompareWrap(targetColl, wcoll, t1, t2); Assert.AreEqual(2, changeCounter); Assert.AreEqual(t2, lastAdd); Assert.AreEqual(NotifyCollectionChangedAction.Add, lastAction); targetColl.Remove(t1); CompareWrap(targetColl, wcoll, t1, t2); Assert.AreEqual(3, changeCounter); Assert.AreEqual(t1, lastRemove); Assert.AreEqual(NotifyCollectionChangedAction.Remove, lastAction); Assert.AreEqual(targetColl.Count, wcoll.Count); }
public sampleListener() { _sampleEventReceiver = new EventReceiver(OnSampleEvent); }
public sampleListener() { _sampleEventReceiver = new EventReceiver(OnSampleEvent); }
private CompoundWeakEvent() { _evt = new WeakEvent(this); trigger = new EventReceiver((x, y) => _evt.Raise(y)); }