Viewing the IL code generated from a compiled expression

╄→尐↘猪︶ㄣ 提交于 2019-11-27 06:41:20

Yes! Use this tool:

https://github.com/drewnoakes/il-visualizer

This was incredibly useful when I was implementing and debugging Compile, as I'm sure you can imagine.

justin.m.chase

Create a DynamicAssembly, then a DynamicModule, DynamicType and DynamicMethod. Make that method public and static and pass it to the method CompileTo() on the lambda. When you make the assembly flag it as Save. Then call the Save() method and pass a path. It will be written to disk. Pop it open in reflector.

Something like:

var da = AppDomain.CurrentDomain.DefineDynamicAssembly(
    new AssemblyName("dyn"), // call it whatever you want
    AssemblyBuilderAccess.Save);

var dm = da.DefineDynamicModule("dyn_mod", "dyn.dll");
var dt = dm.DefineType("dyn_type");
var method = dt.DefineMethod(
    "Foo", 
    MethodAttributes.Public | MethodAttributes.Static);

lambda.CompileToMethod(method);
dt.CreateType();

da.Save("dyn.dll");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!