1
0

Disposable.cs 1.2 KB

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