问题描述
是否可以查看IL code产生的,当你在一个防爆pression树调用编译()?考虑这个非常简单的例子:
Is it possible to view the IL code generated when you call Compile() on an Expression tree? Consider this very simple example:
class Program
{
public int Value { get; set; }
static void Main(string[] args)
{
var param = Expression.Parameter(typeof(Program));
var con = Expression.Constant(5);
var prop = Expression.Property(param, typeof(Program).GetProperty("Value"));
var assign = Expression.Assign(prop, con);
Action<Program> lambda = Expression.Lambda<Action<Program>>(assign, param).Compile();
Program p = new Program();
lambda(p);
//p.Value = 5;
}
}
现在,前pression树做什么主要的最后一行
说。编译应用程序,然后在反射器中打开它。你可以看到 p.Value = 5的IL code;
,做分配。但前pression树制成,在运行时编译。是否有可能从编译查看产生IL code?
Now, the expression tree does what the last line of Main
says. Compile the application, then open it in Reflector. You can see the IL code of p.Value = 5;
that does the assignment. But the expression tree was made and compiled at runtime. Is it possible to view the resulting IL code from the compile?
推荐答案
是的!使用此工具:
http://blogs.msdn.com/b/haibo_luo/archive/2006/11/16/take-two-il-visualizer.aspx
这是非常有用的,当我实现和调试编译,因为我敢肯定,你可以想像的。
This was incredibly useful when I was implementing and debugging Compile, as I'm sure you can imagine.
这篇关于查看从编译前pression产生IL code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!