Getting Started with Roslyn

Introduction

Welcome to today's article. Today, I would like to introduce you to the .NET Compiler Platform, known as Roslyn.

Roslyn

Roslyn is the codename for the .NET Compiler Platform. This platform is a set of code analysis APIs and open-source compilers for Visual Basic.Net and C#. Roslyn enables building code analysis tools with the same APIs that are used by Visual Studio.

The .NET Compiler Platform ("Roslyn") exposes a set of Compiler APIs and Workspaces APIs that provides rich information about your source code and that has full fidelity with the C# and Visual Basic languages. The transition to compilers as a platform dramatically lowers the barrier to entry for creating code focused tools and applications. It creates many opportunities for innovation in areas such as meta-programming, code generation and transformation, interactive use of the C# and VB languages, and embedding of C# and VB in domain specific languages.

Installing Roslyn

Step 1: Download the latest version of Visual Studio. In a later article, I will explain in detail how to do this.

Step 2: Roslyn can be found on GitHub. Simply download the zip file to a specified location on your hard disk. Once the download has completed, extract it to a folder of your choice. It unfortunately takes a while because the zip file is quite big.

Roslyn should now be installed. You may also want to have a look into the zip file's contents that have unzipped earlier. Inside, you will find the samples under the docs folder as well as Roslyn.sln and RoslynLight.sln. RoslynLight.sln represents the source code buildable in the latest public release. Roslyn.sln represents all of the source code.

When you open Visual Studio RC, you will immediately see the Roslyn improvements, which include the following:

'#Region' Directives Inside Method Bodies

Another feature that I have begged for a long time to have is the ability to include a Region inside a method. Here is how you would be able to implement it:

The ?. Operator

Having to check for NULL values, or values that are Nothing, has always been a pain for me, and I believe many a fellow VB. Developer. This operator makes it easy to check for null values in objects. Here is an example of its implementation: