如何使 Reflector 不会因新语法而被阻塞
有没有办法让反射器反汇编回新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
至于自动实现的属性,它们在最新版本中表现良好(即作为
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 setOptimization
to.NET 3.5
or.NET 4.0
inView -> Options -> Disassembler
.并非所有内容都是双向翻译。诸如 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.
显然,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).