From cde9fc6a8fe569203cb991121a35c2a9c7f4c420 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 22 Jan 2013 17:25:22 +0900 Subject: import 2b5dbddd740b, new directory structure in the original rx. --- .../Reactive/AnonymousObservable.cs | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Rx/NET/Source/System.Reactive.Core/Reactive/AnonymousObservable.cs (limited to 'Rx/NET/Source/System.Reactive.Core/Reactive/AnonymousObservable.cs') diff --git a/Rx/NET/Source/System.Reactive.Core/Reactive/AnonymousObservable.cs b/Rx/NET/Source/System.Reactive.Core/Reactive/AnonymousObservable.cs new file mode 100644 index 0000000..81ffa53 --- /dev/null +++ b/Rx/NET/Source/System.Reactive.Core/Reactive/AnonymousObservable.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +using System.Reactive.Disposables; + +namespace System.Reactive +{ + /// + /// Class to create an IObservable<T> instance from a delegate-based implementation of the Subscribe method. + /// + /// The type of the elements in the sequence. + public sealed class AnonymousObservable : ObservableBase + { + private readonly Func, IDisposable> _subscribe; + + /// + /// Creates an observable sequence object from the specified subscription function. + /// + /// Subscribe method implementation. + /// is null. + public AnonymousObservable(Func, IDisposable> subscribe) + { + if (subscribe == null) + throw new ArgumentNullException("subscribe"); + + _subscribe = subscribe; + } + + /// + /// Calls the subscription function that was supplied to the constructor. + /// + /// Observer to send notifications to. + /// Disposable object representing an observer's subscription to the observable sequence. + protected override IDisposable SubscribeCore(IObserver observer) + { + return _subscribe(observer) ?? Disposable.Empty; + } + } +} -- cgit v1.2.3