// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
namespace System.Reactive.Disposables
{
///
/// Represents a disposable resource which only allows a single assignment of its underlying disposable resource.
/// If an underlying disposable resource has already been set, future attempts to set the underlying disposable resource will throw an .
///
public sealed class SingleAssignmentDisposable : ICancelable
{
private SingleAssignmentDisposableValue _current;
///
/// Initializes a new instance of the class.
///
public SingleAssignmentDisposable()
{
}
///
/// Gets a value that indicates whether the object is disposed.
///
public bool IsDisposed => _current.IsDisposed;
///
/// Gets or sets the underlying disposable. After disposal, the result of getting this property is undefined.
///
/// Thrown if the has already been assigned to.
public IDisposable? Disposable
{
get => _current.Disposable;
set => _current.Disposable = value;
}
///
/// Disposes the underlying disposable.
///
public void Dispose()
{
_current.Dispose();
}
}
}