Dave Sexton's Blog

on software development using C# and the Microsoft .NET Framework
Welcome to Dave Sexton's Blog Sign in | Join | Help

Dispose Method Override Snippet

File Details
Downloads: 240 File Size: 1.3kB
Posted By: Dave Sexton Views: 1030
Date Added: Mon, Mar 19 2007

My snippets are provided "as is", with no warranty of any kind, either express or implied.  Use at your own risk.

Creates the canonical Dispose method override code for types that ultimately derive from the System.ComponentModel.Component class.

Shortcut: disposec

For more information on my C# Code Snippets see my blog entry: Custom C# Code Snippets.  All of my snippets may be downloaded at once here.

Usage

This snippet is intended to be used as expansion only from within the body of a class definition. The class must derive, directly or indirectly, from a class with a protected virtual void Dispose(bool disposing) method that is not sealed.

This snippet is useful for classes that derive from System.ComponentModel.Component or derived types such as WinForms Controls. This snippet is not suitable for classes that derive from the ASP.NET Control class.

Example Output

The following code illustrates this snippet's output when it's executed for expansion from within the body of the Person class:

class Person : Component
{
  /// <summary>
  /// Releases the unmanaged resources used by an instance of the <see cref="Person" /> class 
  /// and optionally releases the managed resources.
  /// </summary>
  /// <param name="disposing"><strong>true</strong> to release both managed and 
  /// unmanaged resources; <strong>false</strong> to release only unmanaged resources.</param>
  protected override void Dispose(bool disposing)
  {
    try
    {
      if (disposing)
      {
        | {text cursor goes here}
      }
    }
    finally
    {
      base.Dispose(disposing);
    }
  }
}

Comments
No comments exist for this file.

Add Comment

Name (required)
Web Site (optional)
Comment (required)
Add
Powered by Community Server (Personal Edition), by Telligent Systems