.net反射反编译的C#code将无法编译反射、反编译、net、code

2023-09-02 21:41:25 作者:我可以很潇洒

我试图反编译一个C#控制台应用程序和Visual C#2010重新编译它,但也有在code许多错误。下面是一个例子:

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;
        }
    }

我已经设置了.NET Framework版本3.5在.net反射。有没有什么办法让code,能够从.NET反射器重新编译?

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?

推荐答案

有没有直接的方法来克服这个限制。编译器产生的 IL 从源$ C ​​$ c和本 IL 可能的不可以包含的信息关于你的最初来源$ C ​​$ C。例如,当你写

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; }

它使用特殊符号和名称,你不能使用你的领域在源代码中来命名

编译器创建支持字段(k__BackingField 例如&LT;性&gt) code。你给上面的例子中,在反射器试图推断出编译器的意思。

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.

我用 dotPeek (免费的反编译器由JetBrains公司),并了解autoproperties,所以你会看到正确的code在你的榜样。但再次 - 可能存在的情况下,其中dotPeek将无法获取初始源$ C ​​$ C

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.