Пример #1
0
        public void EmitDelegateTest()
        {
            CodeInstruction instruction = HarmonyWrapper.EmitDelegate <Action>(StaticAssets.TestStaticMethod);

            Assert.AreEqual(OpCodes.Call, instruction.opcode);
            Assert.IsTrue(instruction.operand is MethodInfo);

            instruction = HarmonyWrapper.EmitDelegate <Action>(() => StaticAssets.TestStaticField = 5);

            Assert.AreEqual(OpCodes.Call, instruction.opcode);
            Assert.IsTrue(instruction.operand is MethodInfo);

            CompileInstruction(instruction)();

            Assert.AreEqual(5, StaticAssets.TestStaticField);

            int dummy = 0;

            instruction = HarmonyWrapper.EmitDelegate <Action>(() => dummy = 15);

            Assert.AreEqual(OpCodes.Call, instruction.opcode);
            Assert.IsTrue(instruction.operand is MethodInfo);

            CompileInstruction(instruction)();

            Assert.AreEqual(15, dummy);
        }