1
0

BooleanDisposable.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System.Reactive.Disposables
  5. {
  6. /// <summary>
  7. /// Represents a disposable resource that can be checked for disposal status.
  8. /// </summary>
  9. public sealed class BooleanDisposable : ICancelable
  10. {
  11. // Keep internal! This is used as sentinel in other IDisposable implementations to detect disposal and
  12. // should never be exposed to user code in order to prevent users from swapping in the sentinel. Have
  13. // a look at the code in e.g. SingleAssignmentDisposable for usage patterns.
  14. internal static readonly BooleanDisposable True = new BooleanDisposable(true);
  15. private volatile bool _isDisposed;
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="T:System.Reactive.Disposables.BooleanDisposable"/> class.
  18. /// </summary>
  19. public BooleanDisposable()
  20. {
  21. }
  22. private BooleanDisposable(bool isDisposed)
  23. {
  24. _isDisposed = isDisposed;
  25. }
  26. /// <summary>
  27. /// Gets a value that indicates whether the object is disposed.
  28. /// </summary>
  29. public bool IsDisposed
  30. {
  31. get { return _isDisposed; }
  32. }
  33. /// <summary>
  34. /// Sets the status to disposed, which can be observer through the <see cref="IsDisposed"/> property.
  35. /// </summary>
  36. public void Dispose()
  37. {
  38. _isDisposed = true;
  39. }
  40. }
  41. }