Is there a way in .NET, using Reflection.Emit
, to access the topmost-but-one item from the stack? So if A is topmost, and B next - I want to process B then A. It would be fine to duplicate B above A (since I can simply "pop" the second B when I get to it).
Currently, I am declaring a local:
LocalBuilder loc = il.DeclareLocal(typeof(Foo));
il.Emit(OpCodes.Stloc, loc); // store and pop topmost stack item
// work with (pop) previous stack item
il.Emit(OpCodes.Ldloc, loc); // push old topmost stack item
Is there a route that doesn't need the explicit local?