Creating C# Analyzers - Is EASY
02/10/2019
Creating C# analyzers with the help of Roslyn is very easy. At first it seems a huge learning curve needed because of Roslyn and the complexity of compilers, but in reality, it is much simpler than expected.
There is one more advantage of creating analyzers. It give a perfect environment to practice Test Driven Development (TDD).
Before beginning we need to make sure, that the analyzer extensions are installed to Visual Studio, otherwise we will not have templates and Syntax Visualizer window. To install the SDK simply enable .NET Compiler Platform SDK feature in Visual Studio.
In this post I will show how to create an analyzer, which checks if an if statement or a conditional operator uses equality comparison operator to compare an operand with null. If that is the case, the analyzer will suggest a to replace the comparison with is pattern matching with nulls, which syntax is available with the latest C# version.