<PackageReference Include="System.Reactive" Version="7.0.0-preview.1" />

SingleAssignmentDisposableValue

using System.Runtime.CompilerServices; using System.Threading; namespace System.Reactive.Disposables { [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(0)] public struct SingleAssignmentDisposableValue { private IDisposable _current; public bool IsDisposed => Volatile.Read(ref _current) == BooleanDisposable.True; public IDisposable Disposable { get { return System.Reactive.Disposables.Disposable.GetValueOrDefault(ref _current); } set { if (System.Reactive.Disposables.Disposable.TrySetSingle(ref _current, value) == System.Reactive.Disposables.TrySetSingleResult.AlreadyAssigned) throw new InvalidOperationException(System.Reactive.Strings_Core.DISPOSABLE_ALREADY_ASSIGNED); } } public void Dispose() { System.Reactive.Disposables.Disposable.Dispose(ref _current); } [System.Runtime.CompilerServices.IsReadOnly] public override bool Equals(object obj) { return false; } [System.Runtime.CompilerServices.IsReadOnly] public override int GetHashCode() { return 0; } public static bool operator ==(SingleAssignmentDisposableValue left, SingleAssignmentDisposableValue right) { return false; } public static bool operator !=(SingleAssignmentDisposableValue left, SingleAssignmentDisposableValue right) { return true; } } }