简体   繁体   English

为什么我的 ILSpy 显示不同版本的代码?

[英]why my ILSpy shows a different version of code?

I'm new to C# and .net, sorry if my question sounds stupid.我是 C# 和 .net 的新手,对不起,如果我的问题听起来很愚蠢。

I follow an onlilne tutorial which teaches how to insepect compiled code, below is a snapshot from the instructor:我遵循在线教程,该教程教授如何检查已编译的代码,以下是讲师的快照: 在此处输入图片说明

And below is a screenshot from my pc:下面是我电脑的截图: 在此处输入图片说明

You can see that mine is purely IL code, and even if I change the setting to C#:可以看到我的是纯IL代码,即使我把设置改成C#: 在此处输入图片说明 there is no <Main>d_0 section anymore, and the code is purely C# code.不再有<Main>d_0部分,代码是纯 C# 代码。 so how can I switch to the view so that I can see the "more advanced C# code" just like the instructor's?那么如何切换到视图,以便可以像讲师一样查看“更高级的 C# 代码”?

You're using a more modern version of ILSpy compared to your instructor.与您的讲师相比,您使用的是更现代的 ILSpy 版本。 Your more modern version can better reverse C#'s newer language-features to simpler C# code.您更现代的版本可以更好地将 C# 的较新语言功能反转为更简单的 C# 代码。

For example, older versions of ILSpy could not decompile async methods with await keywords back into single source methods, but instead would show them as their compiled multi-method state-machines (as you're seeing with how TaskAwaiter is exposed in <Main>d_0 ).例如,旧版本的 ILSpy 无法将带有await关键字的async方法反编译回单个源方法,而是将它们显示为已编译的多方法状态机(正如您在<Main>d_0如何TaskAwaiter所看到的TaskAwaiter<Main>d_0 )。

If you want the same display as your instructor you need to use the same version of ILSpy as them.如果您想要与您的讲师相同的显示,您需要使用与他们相同版本的 ILSpy。 From the screenshot it looks like they're using version 4 or earlier of ILSpy - which is very outdated by now.从屏幕截图看来,他们使用的是 ILSpy 4 或更早版本 - 现在已经非常过时了。 You should tell your instructor to get the latest version (as of November 2020 it's version 6.1).您应该告诉您的讲师获取最新版本(截至 2020 年 11 月,它是 6.1 版)。

The ILSpy toolbar has a group of buttons that lets you choose between ILSpy 工具栏有一组按钮,可让您选择

  • Show only public types and members仅显示公共类型和成员
  • Show public, private and internal (the default)显示公共、私有和内部(默认)
  • Show all types and members (including compiler-generated)显示所有类型和成员(包括编译器生成的)

If you pick "Show all types and members" you'll see the compiler-generated class and its MoveNext method even if decompilation of the async feature is enabled.如果您选择“显示所有类型和成员”,即使启用了async功能的反编译,您也会看到编译器生成的类及其 MoveNext 方法。

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

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