convert delegates to lambdas

Explore, browse and analyze .NET assemblies

Moderators: Luke Jefferson, Charles Brown, StephenC, Alex.Davies, Greg.Tillman, melvyn.harbour

convert delegates to lambdas

Postby theperm » Thu Sep 02, 2010 8:17 pm

Can Reflector be made to disassemble delegates to Lambdas?
theperm
 
Posts: 2
Joined: Thu Sep 02, 2010 7:59 pm

Postby Clive Tong » Fri Sep 03, 2010 9:31 am

For a simple example like

Code: Select all
            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

Code: Select all
    Func<int, int> xx = x => x * 3;
Clive Tong
 
Posts: 283
Joined: Thu Dec 04, 2008 5:42 pm

Postby theperm » Fri Sep 03, 2010 10:54 am

Thats strange, i have it set to 4.0 and all i can see are delegates. What gives?
theperm
 
Posts: 2
Joined: Thu Sep 02, 2010 7:59 pm

Postby Clive Tong » Fri Sep 03, 2010 1:47 pm

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

Code: Select all
        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
 
Posts: 283
Joined: Thu Dec 04, 2008 5:42 pm

Postby Clive Tong » Mon Nov 22, 2010 10:44 am

This has now been fixed. The fix will be in the next EAP release.
Clive Tong
 
Posts: 283
Joined: Thu Dec 04, 2008 5:42 pm


Return to .Net Reflector 6.x and .NET Reflector 6.x Pro

Who is online

Users browsing this forum: No registered users and 0 guests