title: Properly disposing an object hierarchy in C#
body: <p>I am working on a project where a certain class hierarchy implements IDisposable.</p>
  
  <p>Some of the classes also implement a Finalize method ( ~MyClass() )</p>
  
  <p>In general it looks something like this:</p>
  
  <pre><code>public class BaseClass : IDisposable
  {
  }
  
  public class SomeClass : BaseClass
  {
      ~SomeClass()
      {
          Dispose();
      }
  
      Dispose()
      {
          // Do some stuff.
          base.Dispose();
      }
  }
  
  public class AnoterClass : SomeClass
  {
      ~AnoterClass()
      {
          Dispose();
      }
  
      Dispose()
      {
          // Do some stuff.
          base.Dispose();
      }
  }
  </code></pre>
  
  <p>I'd like to know what is the proper way of handling calls to Dispose, as it seems that these objects are being disposed by calling Dispose(), and later on crash since the Finalize method is called.</p>
  
  <p>Is it best to keep a flag at the lowest class in the hierarchy (protected bool disposed), and check that in every level of the class hierarchy?</p>
  
  <p>I find that every possible solution requires some code duplication, which is not what i'm after.</p>