Red Gate forums :: View topic - convert delegates to lambdas
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
.Net Reflector 6.x and .NET Reflector 6.x Pro
.Net Reflector 6.x and .NET Reflector 6.x Pro forum

convert delegates to lambdas

Search in .Net Reflector 6.x and .NET Reflector 6.x Pro forum
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
Jump to:  
Author Message
theperm



Joined: 02 Sep 2010
Posts: 2

PostPosted: Thu Sep 02, 2010 8:17 pm    Post subject: convert delegates to lambdas Reply with quote

Can Reflector be made to disassemble delegates to Lambdas?
Back to top
View user's profile Send private message
Clive Tong



Joined: 04 Dec 2008
Posts: 283

PostPosted: Fri Sep 03, 2010 9:31 am    Post subject: Reply with quote

For a simple example like

Code:

            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:

    Func<int, int> xx = x => x * 3;
Back to top
View user's profile Send private message
theperm



Joined: 02 Sep 2010
Posts: 2

PostPosted: Fri Sep 03, 2010 10:54 am    Post subject: Reply with quote

Thats strange, i have it set to 4.0 and all i can see are delegates. What gives?
Back to top
View user's profile Send private message
Clive Tong



Joined: 04 Dec 2008
Posts: 283

PostPosted: Fri Sep 03, 2010 1:47 pm    Post subject: Reply with quote

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:

        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.
Back to top
View user's profile Send private message
Clive Tong



Joined: 04 Dec 2008
Posts: 283

PostPosted: Mon Nov 22, 2010 10:44 am    Post subject: Reply with quote

This has now been fixed. The fix will be in the next EAP release.
Back to top
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies. All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group