Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Core/Reactive/Disposables/Disposable.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 namespace System.Reactive.Disposables
4 {
5 /// <summary>
6 /// Provides a set of static methods for creating Disposables.
7 /// </summary>
8 public static class Disposable
9 {
10 /// <summary>
11 /// Gets the disposable that does nothing when disposed.
12 /// </summary>
13 public static IDisposable Empty
14 {
15 get { return DefaultDisposable.Instance; }
16 }
17
18 /// <summary>
19 /// Creates a disposable object that invokes the specified action when disposed.
20 /// </summary>
21 /// <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>
22 /// <returns>The disposable object that runs the given action upon disposal.</returns>
23 /// <exception cref="ArgumentNullException"><paramref name="dispose"/> is null.</exception>
24 public static IDisposable Create(Action dispose)
25 {
26 if (dispose == null)
27 throw new ArgumentNullException("dispose");
28
29 return new AnonymousDisposable(dispose);
30 }
31 }
32 }