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