反射器和自动属性的问题

发布于 2024-07-20 22:28:57 字数 287 浏览 3 评论 0原文

我刚刚使用 Reflector 反汇编了一个项目来调试它,但似乎不愿解码自动属性的“编译结果”,例如下一行给我一个语法错误。 我尝试过手动修复这些问题,但每次修复一个问题时,都会出现更多问题。

private string <GLDescription>k__BackingField;

我能做些什么吗?

I've just disassembled a project to debug it using Reflector, but it seems to balk at decoding the 'compile results' of automatic properties, e.g. the next line gives me a syntax error. I've tried fixing these manually, but every time I fix one, more appear.

private string <GLDescription>k__BackingField;

Is there anything I can do about this?

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

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

发布评论

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

评论(2

听你说爱我 2024-07-27 22:28:57

哈! 愚蠢的我:我所要做的就是将 Reflector 选项中的反汇编器优化设置为 .NET 3.5。 我的是2.0。

Ha! Stupid me: all I had to do was set the disassembler optimization in Reflector's options to .NET 3.5. Mine was on 2.0.

漫雪独思 2024-07-27 22:28:57

编译器生成具有“难以形容的名称”的字段 - 即在 C# 本身中非法的字段,但在 IL 中是有效的。

没有完全准确地将 IL 转换为“正常”C#(没有自动属性)。 您可以将 <> 替换为 _,这将给出合法的代码,但当然它不会完全正确 不再有相同的代码。 但是,如果您只追求调试能力,那么这不会是问题。

如果您反编译迭代器(即使用 yield 语句的方法),您会发现更多相同内容,包括使用 fault 块,类似于 finally 块,但它们仅在发生异常时运行(但不捕获异常)。 其他各种构造也会生成难以形容的名称,包括匿名方法、lambda 表达式和匿名类型。

更广泛地说,您是否有权反编译此代码? 如果作者不介意您这样做,他们可能愿意为您提供源代码,这将使您的生活更轻松。 如果他们希望您一开始就调试他们的源代码,您应该考虑反编译代码的道德(以及潜在的法律)后果。 这可能因地点而异:咨询真正的律师以获得更明确的指导。

编辑:看到你自己的答案后,这很有意义。 我将把它留在这里作为背景材料。

The compiler generates fields with "unspeakable names" - i.e. ones which are illegal in C# itself, but are valid IL.

There's no exactly accurate translation of the IL into "normal" C# (without automatic properties). You can replace < and > with _ which will give legal code, but then of course it won't be exactly the same code any more. If you're only after the ability to debug, however, that won't be a problem.

If you decompile iterators (i.e. methods using yield statements) you'll find more of the same, including the use of fault blocks, which are like finally blocks but they only run when an exception has occurred (but without catching the exception). Various other constructs generate unspeakable names too, including anonymous methods, lambda expressions and anonymous types.

On a broader note, do you have permission to decompile this code? If the author doesn't mind you doing so, they're likely to be willing to give you the source code to start with which would make your life easier. If they don't want you debugging their source code to start with, you should consider the ethical (and potentially legal) ramifications of decompiling the code. This may vary by location: consult a real lawyer for more definitive guidance.

EDIT: Having seen your own answer, that makes a lot of sense. I'll leave this here for background material.

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