Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq.Expressions;
- using System.Reflection;
- using System.Reflection.Emit;
- public class Program
- {
- private static void Main(string[] args)
- {
- var asm = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("hoge"), AssemblyBuilderAccess.RunAndSave);
- var mod = asm.DefineDynamicModule("hoge.dll");
- var typ = mod.DefineType("typ");
- var met = typ.DefineMethod("met", MethodAttributes.Public | MethodAttributes.Static);
- var exp = Expression.Lambda<Action>(
- Expression.Call(
- typeof(Console).GetMethod(nameof(Console.WriteLine), new[] { typeof(string) }),
- Expression.Constant("Hoge")),
- tailCall: true); // tail
- exp.CompileToMethod(met);
- typ.CreateType();
- asm.Save("Hoge.dll");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement