我有点问题。 我试图在我创建的方法中插入Mono.Cecil的指令集。
Collection<Instruction> InstructionList = new Collection<Instruction>();
添加一个没有操作数的正常指令,例如&#34; Ret&#34;或&#34; ldarg.0&#34;我这样做:
InstructionList.Add(Instruction.Create(OpCodes.Ret));
但是我在创建一个具有像这样的操作数(图像)的指令时遇到了问题:
http://puu.sh/bzWi8/710c8008df.png
有人可以解释我如何使用这些操作数添加指令,例如ldsfld空字符串或br.s或callvirt。
我不知道该怎么做。
我的尝试是这样的:
InstructionList.Add(Instruction.Create(OpCodes.Ldsfld, ModuleDef.Import(typeof(System.String))));
但是抛出了一个异常:类型为&#39; System.ArgumentException&#39;的未处理异常。发生在Mono.Cecil.dll中 附加信息:OpCode
有人可以解释我如何添加这些&#34;更复杂的&#34;说明?
答案 0 :(得分:0)
InstructionList.Add(Instruction.Create(OpCodes.Ret));
它应该是
InstructionList.Add(Instruction.Create(OpCodes.Ret, null));