.net Reflector decompiled C# code won't compile

旧巷老猫 提交于 2019-11-27 08:28:18

问题


I tried to decompile a C# console application and compile it again in Visual C# 2010, but there are many errors in the code. Here is an example:

 public static Test mTest
    {
        [CompilerGenerated]
        get
        {
            return <mTest>k__BackingField;
        }
        [CompilerGenerated]
        set
        {
            <mTest>k__BackingField = value;
        }
    }

I've set the .net framework version to 3.5 in .net Reflector. Is there any way to get code that is able to recompile from .net Reflector?


回答1:


There is no straight way to overcome this limitation. Compiler created IL from your source code and this IL may not contain information regarding your initial source code. For example when you write

public string Property { get; set; }

Compiler creates backing field (for example <Property >k__BackingField ) and names it using special symbols, that you can't use to name your field in the source code. You gave the example above, where reflector tried to deduce what compiler meant.

I've used dotPeek (free decompiler by JetBrains) and it understand autoproperties, so you would see correct code in your example. But again - there might be cases, where dotPeek won't be able to get the initial source code.



来源:https://stackoverflow.com/questions/15555766/net-reflector-decompiled-c-sharp-code-wont-compile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!