Skip to content
| Marketplace
Sign in
Visual Studio>Tools>Dispose Snippet
Dispose Snippet

Dispose Snippet

Robert MacLean

|
4,879 clicks
| (1) | Free
This is a Visual Studio snippet, which provides developers an easier and more complete way to correct implement IDisposable on their classes.
Get Started

Full details on this snippets usage and history can be found at:http://www.sadev.co.za/content/two-new-visual-studio-snippets

If you are implementing a class that needs to inherit IDisposable you can use the the option in VS to implement the methods. However from a proven practices point of view, the Visual Studio support it is lacking since you just get the Dispose method. Now instead of doing that you can use thedispose snippet which produces 41 lines of code which has:

  • Region for the code - same as if you used the VS option
  • Properly implemented Dispose method which calls Dispose(bool) and GC.SuppressFinalize
  • A Dispose(bool) method for cleanup of managed and unmanaged objects
  • A private bool variable to make sure we do not call dispose multiple times.

Installation is as easy as saving to the correct folder which changes depending on your version of Visual Studio:

  • 2005:C:\Users\<Username>\Documents\Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets
  • 2008:C:\Users\<Username>\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets
  • 2010:C:\Users\<Username>\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets
  • 2012: C:\Users\<Username>\Documents\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets
  • 2013: C:\Users\<Username>\Documents\Visual Studio 2013\Code Snippets\Visual C#\My Code Snippets
    • Contact us
    • Jobs
    • Privacy
    • Manage cookies
    • Terms of use
    • Trademarks
    © 2025 Microsoft