Writing an application based on the Compiler Syntax API to parse and transform source files
In this section, we will write a C# console application based on Roslyn Compiler APIs to parse a given source file into a syntax tree, and then perform the following syntax transformations:
- Edit all the class declarations with no explicit accessibility modifier to add an internal modifier.
- Add documentation comment syntax trivia to all public class declarations with no documentation comments.
- Remove empty class declarations with no members.
Getting started
You will need to have the Visual Studio 2017 Community Edition installed on your machine to execute this recipe. You can install a free Community Edition from: https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15.
How to do it...
- Open Visual Studio and create a new C# console application targeting .NET Framework 4.6 or higher, say
ConsoleApp
. - Install the
Microsoft.CodeAnalysis.CSharp
NuGet package (as of this writing...