andrew4582

Dispose Pattern Snippet

Aug 15th, 2010
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.88 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.       <CodeSnippet Format="1.0.0">
  4.             <Header>
  5.                   <Title>AH DisposePattern</Title>
  6.                   <Shortcut>ahDisposePattern</Shortcut>
  7.                   <Description>Code snippet created on: 3/9/2010 10:30:58 AM</Description>
  8.                   <Author>Andrew Hodgson</Author>
  9.                   <SnippetTypes>
  10.                         <SnippetType>Expansion</SnippetType>
  11.                   </SnippetTypes>
  12.             </Header>
  13.             <Snippet>
  14.                   <Declarations>
  15.                         <Literal Editable="false">
  16.                               <ID>classname</ID>
  17.                               <ToolTip>Class name</ToolTip>
  18.                               <Function>ClassName()</Function>
  19.                               <Default>ClassNamePlaceholder</Default>
  20.                         </Literal>
  21.                   </Declarations>
  22.                   <Code Language="csharp">
  23.                         <![CDATA[#region IDisposable
  24.            protected bool IsDisposed { get; private set; }
  25.  
  26.        public virtual void Dispose() {
  27.            if(IsDisposed)
  28.                throw new ObjectDisposedException(this.GetType().Name);
  29.            try {
  30.                this.Dispose(true);
  31.            }
  32.            finally {
  33.                GC.SuppressFinalize(this);
  34.            }
  35.        }
  36.        protected virtual void Dispose(bool disposing) {
  37.            try {
  38.                if(!IsDisposed) {
  39.                    if(disposing) {
  40.                       $end$
  41.                    }
  42.                }
  43.            }
  44.            finally {
  45.                this.IsDisposed = true;
  46.            }
  47.        }
  48.            #endregion]]>
  49.                   </Code>
  50.             </Snippet>
  51.       </CodeSnippet>
  52. </CodeSnippets>
Advertisement
Add Comment
Please, Sign In to add comment