Can Reflector be made to disassemble delegates to Lambdas?
theperm
0

Comments

4 comments

  • Clive Tong
    For a simple example like
                Func<int, int> xx =
                    delegate(int x)
                        {
                            return x*3;
                        };
    

    if the View/Options/Disassembler/Optimization is set to .NET 2.0, you see the code as a delegate, but if you set it to .NET 3
    .5 you see it as a lambda
        Func<int, int> xx = x => x * 3;
    
    Clive Tong
    0
  • theperm
    Thats strange, i have it set to 4.0 and all i can see are delegates. What gives?
    theperm
    0
  • Clive Tong
    You're found a bug, which affects assemblies compiled against the .NET 4 platform.

    The code that decompiles a delegate as a lambda expression, has a guard which checks that the assembly containing the type references System.Query or System.Core.

    Hence the following decompiles to a lambda expression
            static void Main(string[] args)
            {
                Type foo = typeof (System.Linq.Enumerable);
    
                Func<int, int> xx =
                  delegate(int x)
                  {
                      return x * 3;
                  };
            }
    

    but commenting out the typeof line causes Reflector to always decompile to a delegate (as the assembly no longers references out of the assemblies mentioned above).

    I've logged this as RP-760.
    Clive Tong
    0
  • Clive Tong
    This has now been fixed. The fix will be in the next EAP release.
    Clive Tong
    0

Add comment

Please sign in to leave a comment.