Runar Ovesen Hjerpbakk

Science-based software development

.Net Compiler Platform (“Roslyn”): Analyzers and the Rise of Code-Aware Libraries

A code-aware library is a library that provides guidance on correct use through embedded tooling and operates on the user’s code in real time.

This is the spiritual successor to FXCop. The most useful rules are already available on nuget. The future is here. The future is here.

The analyzers are also run inside the preview window. Real preview! Real preview!

By installing the C# essentials extension, an analyzer with a code fix project template is available. The boiler plate is a type name checker which checks that all types start with upper case letters. It also supplies an action to camel case the names. Such a project can be debugged, starting a new session of Visual Studio 2015.

Your first decision is what languages the analyzer should support. I recommend C#, off course.

The AnalysisContext contains the state of the analyzer, will be huge. You can write your code at debug time to better understand the content. Thanks edit and continue. “It now actually works”. It's just code :) It's just code :)

For code fixes, a CodeFixContent context is provided. Using async operations to prevent blocking the UI thread.

Roslyn syntax tree visualizer will help with the code generation in the fixes. The Roslyn syntax APIs are immutable.

If your action do not appear in Visual Studio 2015, delete the ComponentModelCache (MEF cache) to force a refresh.