public void AddVariableIndex() { var object_ref = new TypeReference ("System", "Object", null, null, false); var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); var body = new MethodBody (method); var x = new VariableDefinition ("x", object_ref); var y = new VariableDefinition ("y", object_ref); body.Variables.Add (x); body.Variables.Add (y); Assert.AreEqual (0, x.Index); Assert.AreEqual (1, y.Index); }
public void CreateMethodFromScratch() { IgnoreOnMono (); var module = ModuleDefinition.CreateModule ("Pan", ModuleKind.Dll); var type = new TypeDefinition ("Pin", "Pon", TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed, module.ImportReference (typeof (object))); module.Types.Add (type); var method = new MethodDefinition ("Pang", MethodAttributes.Public | MethodAttributes.Static, module.ImportReference (typeof (string))); type.Methods.Add (method); var body = method.Body; body.InitLocals = true; var il = body.GetILProcessor (); var temp = new VariableDefinition ("temp", module.ImportReference (typeof (string))); body.Variables.Add (temp); il.Emit (OpCodes.Nop); il.Emit (OpCodes.Ldstr, "hello"); il.Emit (OpCodes.Stloc, temp); il.Emit (OpCodes.Ldloc, temp); il.Emit (OpCodes.Ret); body.Instructions [0].SequencePoint = new SequencePoint (new Document (@"C:\test.cs")) { StartLine = 0, StartColumn = 0, EndLine = 0, EndColumn = 4, }; var file = Path.Combine (Path.GetTempPath (), "Pan.dll"); module.Write (file, new WriterParameters { SymbolWriterProvider = new PdbWriterProvider (), }); module = ModuleDefinition.ReadModule (file, new ReaderParameters { SymbolReaderProvider = new PdbReaderProvider (), }); method = module.GetType ("Pin.Pon").GetMethod ("Pang"); Assert.AreEqual ("temp", method.Body.Variables [0].Name); }
public void Emit(OpCode opcode, VariableDefinition variable) { Append (Create (opcode, variable)); }
public Instruction Create(OpCode opcode, VariableDefinition variable) { return Instruction.Create (opcode, variable); }
static int GetVariableIndex(VariableDefinition variable) { return variable.Index; }
void CreateLocalVariable(VariableDefinition variable, SymbolToken local_var_token, int start_offset, int end_offset) { writer.DefineLocalVariable2 ( variable.Name, 0, local_var_token, SymAddressKind.ILOffset, variable.Index, 0, 0, start_offset, end_offset); }
public static Instruction Create(OpCode opcode, VariableDefinition variable) { if (variable == null) throw new ArgumentNullException ("variable"); if (opcode.OperandType != OperandType.ShortInlineVar && opcode.OperandType != OperandType.InlineVar) throw new ArgumentException ("opcode"); return new Instruction (opcode, variable); }