【问题标题】:How to get ILSpy to show compiler generated code如何让 ILSpy 显示编译器生成的代码
【发布时间】:2021-06-24 01:19:11
【问题描述】:

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

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,它没有显示我希望看到的状态机代码:

我怎样才能让它显示compiler generated code

【问题讨论】:

    标签: c# compilation syntactic-sugar ilspy


    【解决方案1】:

    您可以转到“查看->选项”并在“反编译器”选项卡下,取消选中“C#2.0->反编译枚举器(yield return)”:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多