Mono.Cecil.Rocks.MethodBodyRocks.ComputeOffsets C# (CSharp) Method

ComputeOffsets() static private method

static private ComputeOffsets ( MethodBody body ) : void
body Mono.Cecil.Cil.MethodBody
return void
        static void ComputeOffsets(MethodBody body)
        {
            var offset = 0;
            foreach (var instruction in body.Instructions) {
                instruction.Offset = offset;
                offset += instruction.GetSize ();
            }
        }

Usage Example

 private static void OptimizeBranches(MethodBody body)
 {
     MethodBodyRocks.ComputeOffsets(body);
     foreach (Instruction instruction in body.Instructions)
     {
         if (instruction.OpCode.OperandType != OperandType.InlineBrTarget || !MethodBodyRocks.OptimizeBranch(instruction))
         {
             continue;
         }
         MethodBodyRocks.ComputeOffsets(body);
     }
 }