空<> C#类名之前 [英] Empty <> before C# class name

查看:116
本文介绍了空<> C#类名之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修复在.NET 4上反编译的C#代码。不幸的是,在我的工作站上仅安装了.NET 3.5,这可能是以下代码无法编译的原因:

I need to repair C# code that was decompiled on with .NET 4. Unfortunately, on my workstation there is only .NET 3.5 installed and that might be the reason why the following code won't compile:

ReportPage.<>c__DisplayClass26 <>c__DisplayClass = new ReportPage.<>c__DisplayClass26();

这里的<>构造是什么意思?
除了此行外,代码中的任何地方都没有c__DisplayClass26字符串。

What <> construct means here? There are no c__DisplayClass26 strings anywhere in the code except this line. This might mean that this name is constructed from some metainformation that was missed during decompilation.

推荐答案

C#编译器有时必须引入变量,这可能意味着该名称是由反编译过程中丢失的一些元信息构造而成的。 / fields / classs。当他必须这样做时,他会在名称前加上<> ,这样就不会发生名称冲突(对于C#编译器,命名是非法的有两个字符的东西)。例如,对于自动生成的属性, yield 关键字lambda&匿名函数/代理,新的 async 关键字(在Async CTP中引入的关键字,可能会在C#5.0中出现)...

The C# compiler sometime has to introduce variables/fields/classes. When he has to do it, he prepends them <> to their name, so there won't be a name collision (with the C# compiler, it's illegal to name something with those two characters). This happens for example for auto generated properties, the yield keyword, lambda & anonymous functions/delegates, the new async keyword (the one that is introduced in the Async CTP and that will probably be present in C# 5.0)...

现在...奇怪的是,您只有 c__DisplayClass26 。也许您的反编译器没有达到标准。尝试使用 IlSpy 查看代码。

Now... It's strange that you have the c__DisplayClass26 only there. Perhaps your decompiler wasn't up to the par. Try looking at the code with IlSpy.

请查看此pastebin: http://pastebin.com/pTRVyVdp (不是我的)。有一个使用 c__DisplayClass 的示例。文本的前半部分是原始代码,后半部分是反编译代码。您会看到,在这种情况下,它用于关闭。在第32/33行,有一个 [CompilerGenerated]专用密封类<> c__DisplayClass2

Look at this pastebin: http://pastebin.com/pTRVyVdp (it isn't mine). There is an example with c__DisplayClass. In the first half of the text there is the "original" code, in the second half the decompile one. You see, in this case it's used for a closure. At lines 32/33 there is a [CompilerGenerated] private sealed class <>c__DisplayClass2. You should have it too in your code.

Mmmh ... IlSpy太好了:-)通常,它可以从代码中重建原始代码。 CompilerGenerated 代码。

Mmmh... IlSpy is a little too much good :-) Often it's able to reconstruct the "original" code from the CompilerGenerated code.

这篇关于空&lt;&gt; C#类名之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆