如何确定.Net中的场景后面发生了什么 [英] How to determine what happens behind the scene in .Net

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

问题描述

我可以使用什么工具或方法来查看哪些代码像匿名方法或LINQ语句被编译?

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.

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

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) {}
}

反编译为

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;
}

,然后查看<> c__DisplayClass1 <> f_AnonymousType0 了解详情等。

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

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

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