DEV Community

Discussion on: Who am I? Me, the name of the currently executing method in C# (Part 2)

Collapse
 
bugmagnet profile image
Bruce Axtens • Edited

I'm intrigued by Erygin's Dispose pattern too. What he is doing is following C#'s Destructor pattern rather than its Finalizer pattern. See Implementing IDisposable and the Dispose Pattern Properly.

It would be interesting to discover whether a Finalizer would work in the same way for a using block as is done in the Benchmark object.

As for the Dispose taking a second parameter, that is mentioned in the Microsoft documentation Implementing a Dispose method which says

The Dispose(Boolean) overload

In the second overload, the disposing parameter is a Boolean that indicates whether the method call comes from a Dispose method (its value is true) or from a finalizer (its value is false).

The Destructor pattern examples I've seen so far don't use this overload. However, the CodeProject article goes into a lot of detail and does discuss the second form thoroughly.

Collapse
 
katnel20 profile image
Katie Nelson

I looked at that CodeProject article as you suggested. It's very detailed and will take me some time to fully digest. The Microsoft doc seems to be a little more precise. I'm just surprised that to use Dispose correctly, you have to keep track it's usage with your own flag. Seems like old school programming. Whenever I use flags in my stuff, our coding advisor always makes a face!

Thanks again for the information. I'll be sure to use it.