Files
MQTTnet/Source/MQTTnet/Internal/Disposable.cs
T
2022-02-20 21:10:46 +01:00

42 lines
1.0 KiB
C#

// 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.
using System;
namespace MQTTnet.Internal
{
public abstract class Disposable : IDisposable
{
protected bool IsDisposed { get; private set; }
protected void ThrowIfDisposed()
{
if (IsDisposed)
{
throw new ObjectDisposedException(GetType().Name);
}
}
protected virtual void Dispose(bool disposing)
{
}
// This code added to correctly implement the disposable pattern.
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
if (IsDisposed)
{
return;
}
IsDisposed = true;
Dispose(true);
GC.SuppressFinalize(this);
}
}
}