문제

Is there a way to make reflector disassemble back to the new c# constructs?

Auto-Implemented properties are coming out like this:

[CompilerGenerated]
private string <TypeName>k__BackingField;
 public string TypeName
 {
     [CompilerGenerated]
     get
      {
         return this.<TypeName>k__BackingField;
      }
      [CompilerGenerated]
      private set
      {
          this.<TypeName>k__BackingField = value;
      }
 }

Generic Types with Strings ints or objects come out wrong:

Tuple<User,String><User,string>

Not to mention the confusing enumerators that are generated in response to some lambda based code.

Any Ideas? Getting back to the original form would be great, but getting to an equivalent compilable state would be a huge step forward. The above examples aren't valid C# code.

도움이 되었습니까?

해결책

As regards auto-implemented properties, they come out fine (i.e. as get; set; without the compiler-generated backing-field) in the latest version. Just make sure you set Optimization to .NET 3.5 or .NET 4.0 in View -> Options -> Disassembler.

다른 팁

Not everything is a two-way translation. Things like lambda expressions, iterators and auto-implemented properties are syntactic sugar in C# that get compiled into real code for us. It isn't always possibly to take this compiled code and determine what the original code looked like.

If Reflector made assumptions about the code in order to detect the results of these syntactic abstractions and then Microsoft changed the compiler, it would be broken again. Reflector instead appears to choose to base its decompilation on the CLR and language specifications that are less subject to change without prior notice.

Well, obviously, Reflector just doesn’t have that feature yet. It hasn’t even caught up with C# 3.0 yet, much less C# 4.0. Just wait for the next version (if there will be one).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top