Finalize & dispose
Nu er ikke lige ekspert i at skrive dispose og finalize metoder, men er nederstående kode ok, eller burde jeg lave nogle rettelser.På forhånd tak
public class TestOra : IDisposable
{
private bool disposed = false;
private OracleConnection OracleCon = new OracleConnection ();
private OracleCommand OracleCmd = new OracleCommand ();
private OracleDataReader OracleDr;
#region CleanUp Code
public void Dispose ()
{
CleanUp (true);
GC.SuppressFinalize (this);
}
private void CleanUp (bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
if (OracleDr is IDisposable)
{
if (OracleDr != null)
{
OracleDr.Dispose ();
}
}
if (OracleCmd is IDisposable)
{
if (OracleCmd != null)
{
OracleCmd.Dispose ();
}
}
if (OracleCon is IDisposable)
{
if (OracleCon != null)
{
OracleCon.Dispose ();
}
}
}
}
disposed = true;
}
~TestOra ()
{
CleanUp (false);
}
#endregion
}