Skip to content

Instantly share code, notes, and snippets.

@jimschubert
Created December 22, 2011 21:00
Show Gist options
  • Save jimschubert/1511838 to your computer and use it in GitHub Desktop.
Save jimschubert/1511838 to your computer and use it in GitHub Desktop.
Common disposable logic
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>dispose</Title>
<Shortcut>dispose</Shortcut>
<Description>Code snippet for common dispose method(s)</Description>
<Author>James Schubert</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
</Declarations>
<Code Language="csharp"><![CDATA[public void Dispose()
{
// be sure to implement IDisposable
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
// free other state (managed objects);
}
// free your own state (unmanaged objects);
// set large fields to null
}
disposed = true;
}
private bool disposed = false;
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment