Is there a way to determine if an object called GC.SuppressFinalize?
I have an object that looks something like this (fullscreen Dispose template for clarity):
public class ResourceWrapper {
private readonly bool _ownsResource;
private readonly UnmanagedResource _resource;
public ResourceWrapper(UnmanagedResource resource, bool ownsResource) {
_resource = resource;
_ownsResource = ownsResource;
if (!ownsResource)
GC.SuppressFinalize(this);
}
~ResourceWrapper() {
if (_ownsResource)
}
}
If the constructor parameter ownsResourceis equal false, then the finalizer has nothing to do - so it seems reasonable (if a little bizarre) to call GC.SuppressFinalizedirectly from the constructor. However, since this behavior is quirky, I will very tempting to notice it in the comments on the XML document ... and if I want to comment on it, then I have to write a unit test for it.
System.GC (SuppressFinalize, ReRegisterForFinalize), - . , GC.SuppressFinalize , Typemock CLR?