// 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 whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.
///
public sealed class SerialDisposable : ICancelable
{
private SerialDisposableValue _current;
///
/// Initializes a new instance of the class.
///
public SerialDisposable()
{
}
///
/// Gets a value that indicates whether the object is disposed.
///
public bool IsDisposed => _current.IsDisposed;
///
/// Gets or sets the underlying disposable.
///
/// If the SerialDisposable has already been disposed, assignment to this property causes immediate disposal of the given disposable object. Assigning this property disposes the previous disposable object.
public IDisposable? Disposable
{
get => _current.Disposable;
set => _current.Disposable = value;
}
///
/// Disposes the underlying disposable as well as all future replacements.
///
public void Dispose()
{
_current.Dispose();
}
}
}