简体   繁体   English

如何让 ILSpy 显示编译器生成的代码

[英]How to get ILSpy to show compiler generated code

I've written and built this app:我已经编写并构建了这个应用程序:

namespace Test
{
    
    class Program
    {
        static void Main(string[] args)
        {
            var myClass = new MyClass();
            foreach (var item in myClass.CountFrom(1, 4))
            {
                Console.WriteLine(item);                
            }
            Console.Read();
        }
    }

    public class MyClass
    {
        public IEnumerable<int> CountFrom(int start, int limit)
        {
            for (int i = start; i <= limit; i++)
            {
                yield return i;
            }
        }
    }
}

When I view the code in ILSpy, based on the.exe in the bin/Debug folder, it doesn't show the state machine code I was hoping to see:当我在 ILSpy 中查看代码时,基于 bin/Debug 文件夹中的.exe,它没有显示我希望看到的 state 机器代码: 在此处输入图像描述

How can I get it to show the compiler generated code ?我怎样才能让它显示编译器生成的代码

You can go to "View->Option" and under the "Decompiler" tab, you can uncheck "C#2.0->Decompile enumerator(yield return)":您可以 go 到“查看->选项”并在“反编译器”选项卡下,您可以取消选中“C#2.0->反编译枚举器(yield return)”: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM