Created
June 23, 2015 06:50
-
-
Save yamamaya/6e15ce6ceb0fda0dee63 to your computer and use it in GitHub Desktop.
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
<?xml version="1.0" encoding="utf-8"?> | |
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>IDisposable Implementation</Title> | |
<Shortcut>idisp</Shortcut> | |
<Description> | |
How Dispose(bool) should be implemented in a class that uses managed | |
and native resources. | |
</Description> | |
<Author>Gnanamurugan</Author> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal Editable="false"> | |
<ID>class</ID> | |
<Function>ClassName()</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp"> | |
<![CDATA[/// <summary> | |
/// Releases all resources used by an instance of the <see cref="$class$" /> class. | |
/// </summary> | |
/// <remarks> | |
/// This method calls the virtual <see cref="Dispose(bool)" /> method, passing in true, | |
/// and then suppresses | |
/// finalization of the instance. | |
/// </remarks> | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
/// <summary> | |
/// Releases unmanaged resources before an instance of the <see cref="$class$" /> | |
/// class is reclaimed by garbage collection. | |
/// </summary> | |
/// <remarks> | |
/// NOTE: Leave out the finalizer altogether if this class doesn't | |
/// own unmanaged resources itself, but leave the other methods | |
/// exactly as they are. | |
/// This method releases unmanaged resources by calling the virtual | |
/// <see cref="Dispose(bool)" /> method, passing in false. | |
/// </remarks> | |
~$class$() | |
{ | |
Dispose(false); | |
} | |
/// <summary> | |
/// Releases the unmanaged resources used by an instance of the | |
/// <see cref="$class$" /> class and optionally releases the managed resources. | |
/// </summary> | |
/// <param name="disposing">true to release both managed and unmanaged resources; | |
/// false to release only unmanaged resources.</param> | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (disposing) | |
{ | |
// free managed resources | |
/* | |
if (managedResource != null) { | |
managedResource.Dispose(); | |
managedResource = null; | |
} | |
*/ | |
} | |
// free native resources if there are any. | |
}]]> | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment