Microsoft Roslyn vs. CodeDom
Solution 1:
Disclaimer: I work for Microsoft on the Roslyn team.
CodeDom is a precursor to Roslyn, but is only marginally related. Essentially, CodeDom is a simple and (somewhat) langage agnostic way to generate code that was added in .NET 1.0 to support designers (a la WinForms). Because CodeDom was an attempt at providing a unified model that can generate code in C#, VB, and other languages, it lacks high fidelity with any of the languages that it supports (that's why you can't create a switch statement with CodeDom). CSharpCodeProvider.CompileAssemblyFromSource is simply a wrapper around executing csc.exe.
Roslyn is a completely different animal. It is a rewrite of both the C# and VB compilers from the ground up using managed code -- C# in C# and VB in VB (the versions of csc.exe and vbc.exe that ship today are written in native code). The advantage of building them in managed code is that users can reference the real compilers as libraries from .NET applications (no wrappers needed).
While building each component of the compiler pipeline, we've exposed public APIs on top:
- Parser -> Syntax Tree API
- Symbol Table/Metadata Import -> Symbol API
- Binder -> Binding and Flow Analysis APIs
- IL Emitter -> Emit API
Roslyn can be used as a sophisticated C# and VB source code generator, but that's where the similarity to CodeDom ends. The Roslyn Compiler APIs can be used to parse code, perform semantic analysis, compile and evaluate code dynamically, etc.
In addition to the compilers, the Roslyn team is also rebuilding the Visual Studio C# and VB IDE features on top of the public compiler APIs. So, the compiler APIs are rich enough to build the Visual Studio design-time tools, like IntelliSense and the Extract Method refactoring. Also, at layers above the compiler, Roslyn offers services for higher-level analysis or data transformation. For example, there are services for formatting code using the C# and VB formatting rules, or finding all references to a particular symbol within a solution.
Really, there isn't just one special benefit of Roslyn over CodeDom. Where CodeDom filled a very specific code generation need, Roslyn is tackling the entire language tooling space by providing a framework to allow you to build just about any sort of C# or VB language tool you can think of.
Solution 2:
CodeDom allows you to compile - but it doesn't give you the ability to really get information about the code itself (other than compiler errors). Basically, it's a black box where you say "compile this" and it says "I succeeded" or "I failed, here are some errors".
Roslyn allows you to completely inspect and build out the code on the fly. This includes things like being able to see/inspect the comments within a piece of source code, detailed information about the full structure, etc. You can go through and get the entire syntax tree of the source you pass into Roslyn, and do detailed analysis or transformations on it.
Given the full, rich syntax information, you have a huge amount of extra control and flexibility. This is how, for example, the sample works that copies a block of C# code and pastes it as VB.NET code. With Roslyn, you can do more than just compile - you can also manipulate the code itself cleanly. This should make a lot of tooling far simpler to generate, since things like refactorings can be done very simply as the tooling understands the full syntax, including meta information (like comments), and can just work with it directly.