开发者

Empty <> before C# class name

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 b开发者_如何转开发e the reason why the following code won't compile:

ReportPage.<>c__DisplayClass26 <>c__DisplayClass = new ReportPage.<>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.


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)...

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.

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 is a little too much good :-) Often it's able to reconstruct the "original" code from the CompilerGenerated code.


xanatos is correct; you are looking at a class that was automatically generated to implement closure semantics.

My handy guide to interpreting the magic names that the C# compiler generates when it has to make something on your behalf is here:

Where to learn about VS debugger 'magic names'

But again let me emphasize that you should not rely upon this; this is for entertainment purposes only. We reserve the right to change this scheme at any time.


This was a compiler-generated class. It was most likely created from an anonymous delegate or lambda inside of a method of the ReportPage class.

You should be able to see where this is used in your decompiled code, and try to figure out what it's doing to back it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜