如何设置.maxstack指令与ILGenerator?如何使用ILGenerator设置“.maxstack”
例如,一个典型的setter方法具有的.maxstack :
.maxstack 2 // The evaluation stack has a max size of 2
IL_0000: ldarg.0 // the current instance (this)
IL_0001: ldarg.1 // new value
IL_0002: stfld Int32 _someField // stores the new value on _someField
IL_0007: ret // Return to caller
这是可能的元数据集合与ILGenerator
,因为它实际上提供DefineLabel和DeclareLocal,那么为什么没有提供SetMaxStack(short/int)
方法或类似的东西?
如果我无法设置此元数据,Reflecion.Emit
如何确定堆栈的大小?它是否将其设置为最大可能值?或者,也许堆栈在运行时自动扩展?
它不相信你做得对。 DeclareLocal()总是正确的。 –