I'm refactoring some code, unleashing Resharper on it, and came across this:
public virtual void Dispose()
{
this.Dispose();
}
...which R# flags as potentially problematic with "Function is recursive on all paths"
Which makes sense; however, the "official" (straight from the horse's mouth) code is somewhat similar (Dispose calls Dispose):
public void Dispose()
{
Dispose(true);
// This object will be cleaned up by the Dispose method.
// Therefore, you should call GC.SupressFinalize to
// take this object off the finalization queue
// and prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
...that code wont' even compile, though; I get, "No overload for method 'Dispose' takes '1' arguments"
So how can I both implement Dispose() and not make it recursive?
UPDATE
If I try this (from here):
try
{
Dispose(true); //true: safe to free managed resources
}
finally
{
base.Dispose();
}
...I get, "'object' does not contain a definition for 'Dispose'" and "No overload for method 'Dispose' takes '1' arguments"