如何使 Reflector 不会因新语法而被阻塞

发布于 2024-09-15 09:46:46 字数 617 浏览 10 评论 0原文

有没有办法让反射器反汇编回新的 C# 结构?

自动实现的属性如下所示:

[CompilerGenerated]
private string <TypeName>k__BackingField;
 public string TypeName
 {
     [CompilerGenerated]
     get
      {
         return this.<TypeName>k__BackingField;
      }
      [CompilerGenerated]
      private set
      {
          this.<TypeName>k__BackingField = value;
      }
 }

带有字符串整数或对象的通用类型出现错误:

Tuple

更不用说在中生成的令人困惑的枚举器对一些基于 lambda 的代码的响应。

有什么想法吗?回到原始形式固然很好,但达到等效的可编译状态将是向前迈出的一大步。上面的示例不是有效的 C# 代码。

Is there a way to make reflector disassemble back to the new c# constructs?

Auto-Implemented properties are coming out like this:

[CompilerGenerated]
private string <TypeName>k__BackingField;
 public string TypeName
 {
     [CompilerGenerated]
     get
      {
         return this.<TypeName>k__BackingField;
      }
      [CompilerGenerated]
      private set
      {
          this.<TypeName>k__BackingField = value;
      }
 }

Generic Types with Strings ints or objects come out wrong:

Tuple<User,String><User,string>

Not to mention the confusing enumerators that are generated in response to some lambda based code.

Any Ideas? Getting back to the original form would be great, but getting to an equivalent compilable state would be a huge step forward. The above examples aren't valid C# code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无边思念无边月 2024-09-22 09:46:46

至于自动实现的属性,它们在最新版本中表现良好(即作为 get; set; 没有编译器生成的支持字段)。只需确保在 View -> 中将 Optimization 设置为 .NET 3.5.NET 4.0 即可。选项->反汇编器

As regards auto-implemented properties, they come out fine (i.e. as get; set; without the compiler-generated backing-field) in the latest version. Just make sure you set Optimization to .NET 3.5 or .NET 4.0 in View -> Options -> Disassembler.

凡间太子 2024-09-22 09:46:46

并非所有内容都是双向翻译。诸如 lambda 表达式、迭代器和自动实现的属性之类的东西都是 C# 中的语法糖,可以为我们编译成真正的代码。并不总是能够获取此编译后的代码并确定原始代码的样子。

如果 Reflector 对代码做出假设以检测这些语法抽象的结果,然后 Microsoft 更改了编译器,那么它会再次被破坏。相反,Reflector 似乎选择将其反编译基于 CLR 和语言规范,这些规范不太可能在不事先通知的情况下进行更改。

Not everything is a two-way translation. Things like lambda expressions, iterators and auto-implemented properties are syntactic sugar in C# that get compiled into real code for us. It isn't always possibly to take this compiled code and determine what the original code looked like.

If Reflector made assumptions about the code in order to detect the results of these syntactic abstractions and then Microsoft changed the compiler, it would be broken again. Reflector instead appears to choose to base its decompilation on the CLR and language specifications that are less subject to change without prior notice.

淡忘如思 2024-09-22 09:46:46

显然,Reflector 还没有这个功能。它甚至还没有赶上 C# 3.0,更不用说 C# 4.0 了。只需等待下一个版本(如果有的话)。

Well, obviously, Reflector just doesn’t have that feature yet. It hasn’t even caught up with C# 3.0 yet, much less C# 4.0. Just wait for the next version (if there will be one).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文