SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Daniel Grunwald

ILSpy - Query Expressions

ILSpy supports LINQ query expression - we added that feature shortly before the M2 release.

Today, I implemented support for decompiling object initializers and fixed some bugs related to deeply nested lambdas. With these two improvements, query expression translation becomes possible in several more cases.

This screenshot shows Luke Hoban's famous LINQ ray-tracer.

Why are queries related to object initializers? Simple: LINQ queries allow only the use of expressions. When an object initializer is decompiled into multiple statements, there's no way to fit those into a "let" or "select" clause, so query expression translation has to abort.

Another issue with this sample was the deep nesting of the compiler-generated lambdas. Once closures are nested more than two levels deep, the C# compiler starts copying the parent-pointer from one closure into its subclosure ("localsZ.localsY = localsX.localsY;"). This case was missing from the lambda decompilation, so some references to the closure classes were left in the decompiled code. This bug has now been fixed, so nested lambdas should decompile correctly.

We're now close to supporting all features in C# 3.0, the only major missing item is expression tree support. So LINQ queries currently decompile into query syntax only if they're compiled into delegates (LINQ-to-Objects, Parallel LINQ), not if they're compiled into expression trees (LINQ-to-SQL etc.).

Published Apr 22 2011, 11:59 PM by DanielGrunwald
Filed under:

Comments

 

Eamon Nerbonne said:

Looks like ILSpy will turn into something really cool!  I see you've implemented compiled-to-IL lambda decompilation, but not yet compiled-to-expression trees.

Well, I've implemented an expression-tree decompiler :-)

code.google.com/.../expressiontocode

It's not perfect, but I hope that at least the unit tests might be useful almost directly  in ILSpy since they cover quite a few corner cases.  Anything else would be a bonus :-).

May 24, 2011 6:36 PM
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.