private static MethodInfo GetCustomFunc <T1, T2, T3>(Func <T1, T2, T3> target)
        {
            var method   = target.Method;
            var body     = method.GetMethodBody();
            var locals   = body.LocalVariables.OrderBy(x => x.LocalIndex).ToList();
            var resolver = new ILInstructionResolver(method);

            switch (method.Name)
            {
            case nameof(TestMethods.Add_Ovf):
            case nameof(TestMethods.Add_Ovf_Un):
            {
                var instructions = ILInstructionReader.FromMethod(method);
                var parsed       = Enum.TryParse <ILOpCodeValues>(method.Name, out ILOpCodeValues result);
                var opCode       = OpCodeLookup.GetILOpcode((int)result);
                instructions[2] = new ILInstruction()
                {
                    OpCode = opCode
                };

                var compiled = ILEngineOpCodeTestMethodCompiler.CompileMethod(opCode, method, (gen) =>
                    {
                        locals.ForEach(x => gen.DeclareLocal(x.LocalType));
                        instructions.ForEach(x => x.Emit(gen, resolver));
                    });
                return(method);
            }

            default: throw new NotImplementedException();
            }
        }
Пример #2
0
        public CompiledTest(MethodInfo method, OpCodeTestAttribute testAttribute)
        {
            this.Method = method;
            var parsed = Enum.TryParse(method.Name, out ILOpCodeValues ILOpCodeValue);

            this.OpCode = OpCodeLookup.GetILOpcode((int)ILOpCodeValue);
            if (ILOpCodeValue.ToString() != Method.Name)
            {
                throw new NotImplementedException($"Iinvalid Method: '{Method.Name}'. Method names must have a matching IlOpCodeValue");
            }
            this.TestAttribute = testAttribute;
        }
 public void GetILOpcodeDebugNegativeTest()
 {
     var actual = OpCodeLookup.GetILOpcode(300);
 }
 public void GetILOpcodePositiveTest()
 {
     var actual = OpCodeLookup.GetILOpcode(OpCodes.Nop.Value);
     var expected = OpCodes.Nop;
     Assert.IsTrue(actual == expected, $"Actual:{actual}\r\nExpected:{expected}\r\n");
 }