Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Core/Reactive/Disposables/BooleanDisposable.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 /// Represents a disposable resource that can be checked for disposal status.
7 /// </summary>
8 public sealed class BooleanDisposable : ICancelable
9 {
10 // Keep internal! This is used as sentinel in other IDisposable implementations to detect disposal and
11 // should never be exposed to user code in order to prevent users from swapping in the sentinel. Have
12 // a look at the code in e.g. SingleAssignmentDisposable for usage patterns.
13 internal static readonly BooleanDisposable True = new BooleanDisposable(true);
14
15 private volatile bool _isDisposed;
16
17 /// <summary>
18 /// Initializes a new instance of the <see cref="T:System.Reactive.Disposables.BooleanDisposable"/> class.
19 /// </summary>
20 public BooleanDisposable()
21 {
22 }
23
24 private BooleanDisposable(bool isDisposed)
25 {
26 _isDisposed = isDisposed;
27 }
28
29 /// <summary>
30 /// Gets a value that indicates whether the object is disposed.
31 /// </summary>
32 public bool IsDisposed
33 {
34 get { return _isDisposed; }
35 }
36
37 /// <summary>
38 /// Sets the status to disposed, which can be observer through the <see cref="IsDisposed"/> property.
39 /// </summary>
40 public void Dispose()
41 {
42 _isDisposed = true;
43 }
44 }
45 }