I have a little problem. I am trying to insert a Collection of Instructions with Mono.Cecil in the Method I have created.
Collection<Instruction> InstructionList = new Collection<Instruction>();
To add a normal instruction which has no operand like for example "Ret" or "ldarg.0" I just do this:
InstructionList.Add(Instruction.Create(OpCodes.Ret));
But I have problems creating an Instruction which has an Operand like these (Image):
http://puu.sh/bzWi8/710c8008df.png
Can someone explain me how to add an Instruction with these operands, like the ldsfld empty string or br.s or callvirt.
I dont know how to do this.
My attempt was this:
InstructionList.Add(Instruction.Create(OpCodes.Ldsfld, ModuleDef.Import(typeof(System.String))));
But that throws an exception: An unhandled exception of type 'System.ArgumentException' occurred in Mono.Cecil.dll Additional information: OpCode
Can someone explain me how to add these "more complex" instructions?