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

SerialDisposable

public sealed class SerialDisposable : ICancelable, IDisposable
Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.
using System.Runtime.CompilerServices; namespace System.Reactive.Disposables { public sealed class SerialDisposable : ICancelable, IDisposable { private SerialDisposableValue _current; public bool IsDisposed => _current.IsDisposed; [System.Runtime.CompilerServices.Nullable(2)] public IDisposable Disposable { [System.Runtime.CompilerServices.NullableContext(2)] get { return _current.Disposable; } [System.Runtime.CompilerServices.NullableContext(2)] set { _current.Disposable = value; } } public void Dispose() { _current.Dispose(); } } }