Even-class element syntax shown in ILSpy

I loop through several dlls under XNA using ILSpy and stumbled upon this:

class KerningHelper { private void !KerningHelper() { ((IDisposable)this).Dispose(); } } 

What is the exclamation mark in the above? Is this a problem with ILSpy or something else?

Note: the class has a separate destructor: private unsafe void ~KerningHelper() .

+6
source share
1 answer

As indicated in the comments, the exclamation mark is a C ++ / CLI marker for the finalizer method. Unlike traditional C ++ (~) destructors that are called when an object is explicitly deleted, finalizers are called by the garbage collector stream. You can see the official data here .

I would expect ILSpy to translate !KerningHelper() to ~KerningHelper() , since the C ++ / CLI finalizer is equivalent to C # destructor - this is a non-deterministic method that occurs when the GC gets to it, unlike explicit ~ C + + / CLI ~ destructor called when delete called or an explicit call to Dispose.

+5
source

Source: https://habr.com/ru/post/913397/


All Articles