1

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?

4

1 回答 1

4

没有直接的方法可以克服这个限制。从您的源代码创建的编译器IL,这IL可能包含有关您的初始源代码的信息。例如当你写

public string Property { get; set; }

编译器创建支持字段(例如<Property >k__BackingField)并使用特殊符号对其进行命名,您不能在源代码中使用这些符号来命名您的字段。您给出了上面的示例,其中反射器试图推断编译器的含义。

我使用了 dotPeek(JetBrains 的免费反编译器),它理解自动属性,因此您会在示例中看到正确的代码。但同样 - 可能存在 dotPeek 无法获取初始源代码的情况。

于 2013-03-21T18:55:35.640 回答