/// <summary> /// コンストラクタ /// </summary> /// <param name="source">INotifyCollectionChangedオブジェクト</param> public CollectionChangedEventListener([NotNull] INotifyCollectionChanged source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } _bag = new AnonymousCollectionChangedEventHandlerBag(source); Initialize( h => source.CollectionChanged += h, h => source.CollectionChanged -= h, (sender, e) => { if (e != null) { _bag.ExecuteHandler(e); } }); }
/// <summary> /// コンストラクタ。リスナのインスタンスの作成と同時にハンドラを一つ登録します。 /// </summary> /// <param name="source">INotifyCollectionChangedオブジェクト</param> /// <param name="handler">NotifyCollectionChangedイベントハンドラ</param> public CollectionChangedEventListener(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler) { _bag = new AnonymousCollectionChangedEventHandlerBag(source, handler); Initialize(h => source.CollectionChanged += h, h => source.CollectionChanged -= h, (sender, e) => _bag.ExecuteHandler(e)); }