2

In C#, one can construct LINQ queries in so-called "query syntax", e.g.:

var namesOfGoodStudents = from student in students
                          where student.score > 90
                          select student.name;

According to the documentation, this is in fact syntactic sugar, which is "expanded" / "compiled" / "de-sugared" to the following "method syntax":

var namesOfGoodStugents = students
                          .Where(student => student.score > 90)
                          .Select(student => student.name);

This is a pretty straight-forward example, but I sometimes come accross much more complex cases, with multiple from, group and let clauses, where it is not clear (to me, at least) what exactly the query actually gets translated to.

Is there a publicly available tool I could use, where one feeds in a query-syntax LINQ query, and then shown what the translated, de-sugared, method-syntax version of the query is?

Clarification I: I'm not interested in the expansion of a specific example, but in a tool I'd be able to use whenever I encounter one.

Clarification II: A detailed enough description of a conversion algorithm I could manually follow myself in order to translate any query-syntax LINQ query to method syntax would also be considered a great answer :-)

EDIT: Thanks for the possible duplicate reference. The accepted answer there is (currently, at least) LINQPad, which, in addition to being much much heavier than what I'm looking for, doesn't work for me because it's Windows only. Ideally I'd like an online tool, or if that's not to be found then at least something that works cross-platform. The other answers there have actually proven useful for me to some extent, but I was hoping for something better: it is my understanding that translating query syntax to method syntax is a purely syntactical transformation, which one should be able to perform without actually compiling and running the program (the compiler does it as part of the compilation, so surely one shouldn't have to compile and run in order to be able to do that), and without having to supply the actual types and variables. I'm looking for something that can deal with the queries themselves, requiring no further context (e.g. in the example above, do the translation having only the query as input, not needing the [supposed] Student class and the students variable).

Tom
  • 4,910
  • 5
  • 33
  • 48
  • I see my question has been marked a duplicate. I can see how this is reasonale considering the question itself, but, as explained in my edit, the answers to the original question might not be good enough. I need a tool which is cross platform, and ideally won't require supplying the actual classes and variables. Since the original question did not require that and the OP there accepted an answer not satisfying these constraints, this might in fact be considered a separate question. – Tom Apr 03 '17 at 08:06

0 Answers0