Hi,
I have a class which implements dispose patteren. Please see the sample code below.
public class MyClass : IDisposable
{
private readonly IBanking mybanking;
public MyClass(IBanking banking)
{
if (banking == null)
{
throw new ArgumentNullException("banking");
}
mybanking = banking;
}
~MyClass()
{
Dispose(false);
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
protected virtual void Dispose(bool disposing)
{
if (!IsDisposed && disposing)
{
// Dispose your objects
mybanking = null;
}
}
private bool IsDisposed { get; set; }
}
Like MyClass, I have many classes which will implement the same dispose pattern and dispose there won objects.
Can we write a reusable code for dispose pattern. I think we can write it using generic. But not getting how to write.
Can anyone has any idea?
Regards,