Пример #1
0
        public virtual IDisposable Subscribe(IObserver <T> observer)
        {
            var factory = new Lazy <PropertyChangedEventHandler>(() =>
            {
                PropertyChangedEventHandler handler = (s, e) =>
                {
                    if (e.PropertyName == PropertyName)
                    {
                        observer.OnNext(GetValue());
                    }
                };

                Source.PropertyChanged += handler;

                return(handler);
            });

            PropertyChangedEventHandler handler = Observers.GetOrAdd(observer, _ => factory.Value);

            return(Disposable.Create(() => Source.PropertyChanged -= handler));
        }