简体   繁体   English

.net Reflector反编译的C#代码将无法编译

[英].net Reflector decompiled C# code won't compile

I tried to decompile a C# console application and compile it again in Visual C# 2010, but there are many errors in the code. 我试图反编译C#控制台应用程序并在Visual C#2010中再次编译它,但代码中有很多错误。 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. 我在.net Reflector中将.net框架版本设置为3.5。 Is there any way to get code that is able to recompile from .net Reflector? 有没有办法获得能够从.net Reflector重新编译的代码?

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. 编译器从您的源代码创建IL ,此IL可能包含有关您的初始源代码的信息。 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. 编译器创建支持字段(例如<Property >k__BackingField )并使用特殊符号命名它,您不能使用它来命名源代码中的字段。 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. 我使用了dotPeek (JetBrains的免费反编译器)并且它理解autoproperties,所以你会在你的例子中看到正确的代码。 But again - there might be cases, where dotPeek won't be able to get the initial source code. 但同样 - 可能会出现dotPeek无法获取初始源代码的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM