Created
July 19, 2012 20:08
-
-
Save philcockfield/3146438 to your computer and use it in GitHub Desktop.
Full implementation of IDisposable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MonoTouch.Foundation; | |
namespace Core | |
{ | |
public class Foo : NSObject, IDisposable | |
{ | |
public Foo() | |
{ | |
} | |
~Foo() | |
{ | |
Dispose(false); | |
} | |
public bool IsDisposed { get; private set; } | |
public void Dispose() | |
{ | |
base.Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
protected new virtual void Dispose(bool isDisposing) | |
{ | |
// Setup initial conditions. | |
if (IsDisposed) return; | |
// Perform disposal or managed resources. | |
if (isDisposing) | |
{ | |
// Dispose of managed resources. | |
} | |
// Finish up. | |
IsDisposed = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Light weight Disposable implementation.
public class Bar : NSObject, IDisposable
{
public void Dispose()
{
base.Dispose(true);
GC.SuppressFinalize(this);
}
}