IL Wierdness
I am in deep dive mode into Dynamic Proxy 2, and I am once again confronted with IL Madness. I can understand IL well enough to say that this piece of could is a very long way to say: "Console.WriteLine('a');". The problem is that it doesn't do that.
IL_0001: ldc.i4.s 97
IL_0003: box [mscorlib]System.Char
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: unbox [mscorlib]System.Char
IL_000f: stloc.1
IL_0010: ldloc.1
IL_0011: call void [mscorlib]System.Console::WriteLine(char)
IL_0016: nop
IL_0017: ret
Instead, it just prints a random character. The issue is with IL_000a, where the unbox reside. The C# Compiler output an unbox.any in this scenario, and then it works. Pursuing the documenation for those instructions doesn't reveal much. unbox.any is basically an unbox followed with ldobj in this scenario, and unbox short circuit itself to just copy the address of the boxed value.
What this looks to me is that I'm actually storing the reference to the char variable, but I have no idea why. Any explanation is welcome.
Comments
Comment preview