如何确定现场的.Net背后会发生什么 [英] How to determine what happens behind the scene in .Net

查看:87
本文介绍了如何确定现场的.Net背后会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用哪些工具或方法,看看有什么code像匿名方法或LINQ语句被编译成? Basicly看到幕后发生了什么?

What tool or method can I use to see what code something like an anonymous method or LINQ statement gets compiled to? Basicly seeing what happens behind the scene?

推荐答案

反射是一个很好的方式来做到这一点。

Reflector is an excellent way to do this.

转至查看/选项/优化选择无,这样它不会试图制定出C#原本是什么。

Go to View / Options / Optimization and choose "None" so that it won't try to work out what the C# originally was.

例如,这个小应用程序的方法:

For example, the Main method of this little app:

using System;

class Test    
{
    static void Main()
    {
        string other = "hello";
        Foo (x => new { Before = other + x, After = x + other });
    }

    static void Foo<T>(Func<int, T> func) {}
}

被反编译为:

is decompiled to:

private static void Main()
{
    <>c__DisplayClass1 class2;
    class2 = new <>c__DisplayClass1();
    class2.other = "hello";
    Foo(new Func<int, <>f__AnonymousType0<string, string>>(class2.<Main>b__0));
    return;
}

,然后你看看&LT;&GT; c__DisplayClass1 &LT;&GT; f_AnonymousType0 有关详细信息,等等。

and then you look in <>c__DisplayClass1 and <>f_AnonymousType0 for more details etc.

这篇关于如何确定现场的.Net背后会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆