コード例 #1
0
        public static IEnumerable <CodeInstruction> TestTryFinallyTranspiler(IEnumerable <CodeInstruction> instructionEnumerable, MethodBase method, ILGenerator ilGenerator)
        {
            var context      = new TranspilerContext <CodeInstruction>(ilGenerator, method, instructionEnumerable);
            var instructions = context.Instructions;

            instructions.ToDebugString().Log("before");
            context.AddTryFinally(HarmonyTranspilerDebugExtensions.StringLogInstructions("hello world"));
            instructions.ToDebugString().Log("after");
            return(instructions);
        }
コード例 #2
0
        public static IEnumerable <CodeInstruction> TestDeReOptimizeLocalVarTranspiler(IEnumerable <CodeInstruction> instructionEnumerable, MethodBase method, ILGenerator ilGenerator)
        {
            var context          = new TranspilerContext <CodeInstruction>(ilGenerator, method, instructionEnumerable);
            var origInstructions = context.Instructions.ToList();
            var instructions     = context.Instructions;

            instructions.ToDebugString().Log("before deoptimize");
            context.DeoptimizeLocalVarInstructions();
            instructions.ToDebugString().Log("after deoptimize");
            context.ReoptimizeLocalVarInstructions();
            instructions.ToDebugString().Log("after reoptimize");
            CollectionAssert.AreEqual(origInstructions, instructions);
            instructions.SafeInsertRange(instructions.Count - 1, HarmonyTranspilerDebugExtensions.StringLogInstructions("hello world"));
            instructions.ToDebugString().Log("after");
            return(instructions);
        }