diff options
Diffstat (limited to 'Rx.NET/System.Reactive.Core/Reactive/Disposables/Disposable.cs')
-rw-r--r-- | Rx.NET/System.Reactive.Core/Reactive/Disposables/Disposable.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Rx.NET/System.Reactive.Core/Reactive/Disposables/Disposable.cs b/Rx.NET/System.Reactive.Core/Reactive/Disposables/Disposable.cs new file mode 100644 index 0000000..fc77f3b --- /dev/null +++ b/Rx.NET/System.Reactive.Core/Reactive/Disposables/Disposable.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +namespace System.Reactive.Disposables +{ + /// <summary> + /// Provides a set of static methods for creating Disposables. + /// </summary> + public static class Disposable + { + /// <summary> + /// Gets the disposable that does nothing when disposed. + /// </summary> + public static IDisposable Empty + { + get { return DefaultDisposable.Instance; } + } + + /// <summary> + /// Creates a disposable object that invokes the specified action when disposed. + /// </summary> + /// <param name="dispose">Action to run during the first call to <see cref="IDisposable.Dispose"/>. The action is guaranteed to be run at most once.</param> + /// <returns>The disposable object that runs the given action upon disposal.</returns> + /// <exception cref="ArgumentNullException"><paramref name="dispose"/> is null.</exception> + public static IDisposable Create(Action dispose) + { + if (dispose == null) + throw new ArgumentNullException("dispose"); + + return new AnonymousDisposable(dispose); + } + } +} |