internal PencilMethod(ITypeLoader typeLoader, MethodBase method, IType returnType, PencilMethodBody body) { this.typeLoader = typeLoader; this.method = method; this.body = body; this.returnType = returnType; }
public void decode_method() { var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Pencil.Generated"), AssemblyBuilderAccess.ReflectionOnly); var module = assembly.DefineDynamicModule("Pencil.Generated"); var method = module.DefineGlobalMethod("Return42", MethodAttributes.Static | MethodAttributes.Public, typeof(int), System.Type.EmptyTypes); var il = method.GetILGenerator(); il.Emit(OpCodes.Ldc_I4, 42); il.Emit(OpCodes.Ret); module.CreateGlobalFunctions(); var expected = new[] { "ldc.i4 42", "ret" }; var body = new PencilMethodBody(module.GetMethod("Return42")); var actual = body.DecodeBody(new DefaultTypeLoader()); Assert.That(actual.Map(x => x.ToString()).ToList(), Is.EquivalentTo(expected)); }
public IMethod FromNative(ConstructorInfo ctor) { var body = new PencilMethodBody(ctor); return new PencilMethod(this, ctor, FromNative(ctor.DeclaringType), body); }
public IMethod FromNative(MethodInfo method) { var body = new PencilMethodBody(method); return new PencilMethod(this, method, FromNative(method.ReturnType), body); }