Geeks With Blogs

News

View Anthony Trudeau's profile on LinkedIn

Add to Technorati Favorites


Anthony Trudeau

I had some time today when my wife was at the mall to play around with the code snippets finally.  I think I've really missed out on something by not getting into them sooner.  But, hey, I'm like a kid with a new toy.  My first creation is the disposing pattern that I use frequently.

<?xml version="1.0" encoding="utf-8"?>
<
CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
     <
CodeSnippet Format="1.0.0">
          <
Header><Title> Disposing pattern </Title>
               <
Description>Implement the disposing pattern with the corresponding finalizer (destructor).</Description>
               <
Keywords>
                   <
Keyword>Dispose</Keyword>
                   <
Keyword>Finalizer</Keyword>
                   <
Keyword>Destructor</Keyword>
              </
Keywords>
              <
Author>Anthony Trudeau</Author>
         </
Header>
         <
Snippet>
         <
Declarations>
              <
Literal Editable="true">
                  <
ID>ClassName</ID>
                  <
Function>ClassName()</Function>
             </
Literal>
        </
Declarations>
        <
Code Language="CSharp">
            <![CDATA[
~$ClassName$()
{
     Dispose(false);
}

public void Dispose()
{
     Dispose(true);
     GC.SuppressFinalize(this);
}

private bool _disposed; // indicates if Dispose has been called

private void Dispose(bool disposing)
{
     if (!_disposed)
    {
          if (disposing)
         {
              // TODO: cleanup managed resources in $ClassName$
         }

         // TODO: cleanup unmanaged resources in $ClassName$
        _disposed = true;
     }
            }
]]>
        </
Code>
       </
Snippet>
    </
CodeSnippet>
</
CodeSnippets>

 

Posted on Saturday, April 15, 2006 3:05 PM .NET | Back to top


Comments on this post: Disposing pattern code snippet

# re: Disposing pattern code snippet
Requesting Gravatar...
thank you!
Left by omarazam on Mar 25, 2009 11:07 AM

# re: Disposing pattern code snippet
Requesting Gravatar...
Very Nice, Thanks!
Left by Tristen on Jul 15, 2009 9:39 AM

# re: Disposing pattern code snippet
Requesting Gravatar...
You're welcome. I'm glad I could be of assistance.
Left by Anthony Trudeau on Jul 15, 2009 10:12 AM

Your comment:
 (will show your gravatar)


Copyright © Anthony Trudeau | Powered by: GeeksWithBlogs.net