private IDisposable Subscribe(IObserver <CollectionNotification <KeyValuePair <TKey, TValue> > > observer, bool startWithExisting) { Contract.Requires(observer != null); Contract.Ensures(Contract.Result <IDisposable>() != null); lock (gate) { if (isDisposed) { return(Observable .Throw <CollectionNotification <KeyValuePair <TKey, TValue> > >(new ObjectDisposedException("DictionarySubject<TKey, TValue>")) .Subscribe(observer)); } if (exception != null) { return(Observable .Throw <CollectionNotification <KeyValuePair <TKey, TValue> > >(exception) .Subscribe(observer)); } if (startWithExisting) { var clonedList = dictionary.ToList().AsReadOnly(); observer.OnNext(CollectionNotification.CreateDictionaryExists(clonedList)); } return(subject.Subscribe(observer)); } }