Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view c# compiler output of syntactic sugar

I'm looking to see if there is a method or tool to view how things like closures or query expressions are created by the c# compiler "under the hood". I've noticed that many blog posts dealing with these issues will have the original code with syntactic sugar and the underlying c# code that the compiler converts that to. So for example with linq and query expressions they would show:

var query = from x in myList select x.ToString();

then the resulting code would be

var query = myList.Select(x=>x.ToString());

Is it possible with a tool or do you just have to know how it works from the spec and go from there?

like image 975
Matt Phillips Avatar asked Feb 08 '11 21:02

Matt Phillips


1 Answers

Resharper can do this conversion (LINQ expression syntax to lambda syntax) for you very easily.

LINQPad has a tab that can show you the lambda expression syntax for a query you enter into it, and it has another tab that disassembles it all the way down to the IL code level. (There's another tab that shows you the SQL that gets generated if you're using LINQ to SQL or LINQ to Entities).

like image 176
StriplingWarrior Avatar answered Sep 24 '22 10:09

StriplingWarrior