Skip to content

Instantly share code, notes, and snippets.

@ChaseFlorell
Last active August 11, 2021 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChaseFlorell/ba0aaea74f5b60faa96273b0adbe75c7 to your computer and use it in GitHub Desktop.
Save ChaseFlorell/ba0aaea74f5b60faa96273b0adbe75c7 to your computer and use it in GitHub Desktop.
using System;
using System.Reactive.Disposables;
namespace cannect.Core
{
public class DisposableObject : ICancelable
{
public bool IsDisposed { get; private set; }
public void Dispose()
{
DisposeCheck(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
TrashBin.Dispose();
}
}
protected CompositeDisposable TrashBin { get; } = new();
private void DisposeCheck(bool disposing)
{
if (IsDisposed)
{
return;
}
Dispose(disposing);
IsDisposed = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment