Sadly I can't explain them in a better way... So if someone can correct me then thanks!
What in .NET is called a "reference", in C would be called a "pointer". So what is called object me
in C#, would be a void *me
, a pointer (called me
) to an object.
TypedReference tr = __makeref(me);
This creates a TypedReference
to the variable me
. As I've said, a reference is very similar to a C pointer (and in fact if you take a look at is source code you will see that it contains a IntPtr Value
). So in C it would be:
void **tr = &me;
(in .NET a pointer to a TypedReference
, in C a pointer to a pointer)
Now the code is creating a third level of indirectness
void ***temp = &tr;
And then it is dereferencing it twice
void *ptr = **temp;
So we have a *ptr
that is the same as the initial *me
. We are doing it this way because normally in C# you can't directly convert a reference to the equivalent pointer.
Why are they doing this? Because you normally can't cast a reference to a pointer (you can't (IntPtr)me
), nor you can take directly the address of reference (so you can't &me
). But you can create a TypedRefence
that is equivalent to doing &me
. Now, sadly you can't do (IntPtr*)tr
, or (IntPtr)tr
. But fortunately you can &tr
. Now finally you have been able to obtain a real pointer, and you can begin derefencing it to return to the initial pointer that you want.