Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there built-in "simplifications" with Roslyn?

Tags:

c#

roslyn

Is there any built-in way to use Roslyn to perform the same compile-time transformations that the C# compiler does, e.g. for transforming iterators, initializers, lambdas, LINQ, etc. into basic C# code?

like image 214
user541686 Avatar asked Jul 15 '12 17:07

user541686


2 Answers

The Roslyn compiler API is designed to (in addition to translating source code to IL) let you build source code analysis and transformations tools.

However, lambdas and iterators do not have translations that can always be specified using source. They are modeled using the internal bound node abstraction that includes additional compiler specific rules that can only be represented using IL.

It would be possible to translated LINQ to source in C#, since it is specified as a source code translation (whether the compiler actually does it that way or not.) Yet, there is no compiler API that does this specifically. If there was, it would probably show up as a services layer API and not a compiler API.

like image 89
Matt Warren Avatar answered Nov 17 '22 02:11

Matt Warren


AFAIK, no, there is no such thing exposed in Roslyn. But the compiler has to do these transformations somehow, so it's possible you will be able to do this by accessing some internal method.

Of course, you could use Roslyn to make these transformations yourself, but that's not what you're asking.

like image 31
svick Avatar answered Nov 17 '22 02:11

svick