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

问题描述

我已经编写并构建了这个应用程序:

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

当我在 ILSpy 中查看代码时,基于 bin/Debug 文件夹中的 .exe,它没有显示我希望看到的状态机代码

enter image description here

如何让它显示 compiler generated code

解决方法

您可以转到“View->Option”并在“Decompiler”选项卡下,取消选中“C#2.0->Decompile enumerator(yield return)”: enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...