Click to See Complete Forum and Search --> : [MSIL] Get the address of the element on the top of the stack


GameZelda
May 9th, 2010, 04:09 PM
I'm trying to write something equivalent to the following in MSIL:


Console.ReadKey().KeyChar


However, after I call the ReadKey() method and I have the ConsoleKeyInfo on the stack, I haven't found any way to get its address that doesn't involve using a local variable. Is it possible?

Here's what I have:


gen.Emit(OpCodes.Call, typeof(Console).GetMethod("ReadKey", Type.EmptyTypes));
gen.Emit(OpCodes.Stloc_0);
gen.Emit(OpCodes.Ldloca, (ushort)0);
gen.Emit(OpCodes.Call, typeof(ConsoleKeyInfo).GetProperty("KeyChar").GetGetMethod());