Lap Around Roslyn CTP: Introduction
Join the DZone community and get the full member experience.Join For Free
roslyn project is the microsoft implementation of c# and vb
compilers-as-a-service. roslyn provides a transparent view into the
inner workings of the compiler, including syntax tree inspection and
an initial ctp of roslyn has been released for download a couple of days ago—it requires visual studio 2010 sp1 and the vs2010 sp1 sdk .
some of the scenarios enabled by roslyn are the following:
refactoring . refactoring tools no longer need to parse the original source code and then reconstruct it manually. instead, a set of rewriting apis is available on the syntax tree level, making possible classical refactorings—“make readonly”, “extract method”, “extract interface”—as well as incredible new things yet to be invented.
code analysis . performing static code analysis—especially when data flow and control flow are involved—is an extremely difficult task without the syntactic and semantic compiler engines. it becomes possible to answer questions like “is this local variable returned from the method?”, “is this parameter assigned in this specific block under that specific condition?”, “is this method invoked with a compile-time constant expression?”.
“quick fix” . visual studio extensions that run in the background can detect common source code issues and suggest a fix.
repl (read-eval-print loop) . to test code quickly against a given api or to invent a new api and then try it out is easier than ever with the c# interactive window in visual studio. it is more powerful than the immediate window, because you can use the full power of the language—including lambdas and query comprehensions—and because you can define new types or methods and immediately use them.
scripting . roslyn ships with a command-line tool called rcsi.exe that evaluates .csx files—script files written in c# that are clear of the “class program … void main” clutter and focus on exactly the task at hand. i’ll go as far as saying that this is serious competition for powershell!
embedded compiler . it is now easier to embed the c# compiler in an application and provide an ambient context (host object model) implicitly to the compiled code. think dsls and rule engines—taking advantages of the full power of c#.
in the next couple of posts we’ll perform some experimentation with the roslyn apis. if you are looking for more, right away, then go ahead and read the “getting started” documents and the samples that ship with the ctp.
Published at DZone with permission of Sasha Goldshtein, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.