Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/GroupedObservable.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 using System.Reactive.Disposables;
4 using System.Reactive.Subjects;
5
6 namespace System.Reactive.Linq
7 {
8 class GroupedObservable<TKey, TElement> : ObservableBase<TElement>, IGroupedObservable<TKey, TElement>
9 {
10 private readonly TKey _key;
11 private readonly IObservable<TElement> _subject;
12 private readonly RefCountDisposable _refCount;
13
14 public GroupedObservable(TKey key, ISubject<TElement> subject, RefCountDisposable refCount)
15 {
16 _key = key;
17 _subject = subject;
18 _refCount = refCount;
19 }
20
21 public GroupedObservable(TKey key, ISubject<TElement> subject)
22 {
23 _key = key;
24 _subject = subject;
25 }
26
27 public TKey Key
28 {
29 get { return _key; }
30 }
31
32 protected override IDisposable SubscribeCore(IObserver<TElement> observer)
33 {
34 if (_refCount != null)
35 {
36 //
37 // [OK] Use of unsafe Subscribe: called on a known subject implementation.
38 //
39 var release = _refCount.GetDisposable();
40 var subscription = _subject.Subscribe/*Unsafe*/(observer);
41 return new CompositeDisposable(release, subscription);
42 }
43 else
44 {
45 //
46 // [OK] Use of unsafe Subscribe: called on a known subject implementation.
47 //
48 return _subject.Subscribe/*Unsafe*/(observer);
49 }
50 }
51 }
52 }