<PackageReference Include="System.Reactive" Version="4.1.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.
public IDisposable Disposable { get; set; }

Gets or sets the underlying disposable.

public bool IsDisposed { get; }

Gets a value that indicates whether the object is disposed.

Initializes a new instance of the SerialDisposable class.

public void Dispose()

Disposes the underlying disposable as well as all future replacements.