Tutorial by Examples

First obtain the Microsoft.CodeAnalysis.CSharp.Workspaces nuget before continuing. var workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create(); var project = await workspace.OpenProjectAsync(projectFilePath); var compilation = await project.GetCompilationAsync(); foreach (var diag...
A Syntax Tree is an immutable data structure representing the program as a tree of names, commands and marks (as previously configured in the editor.) For example, assume a Microsoft.CodeAnalysis.Compilation instance named compilation has been configured. There are multiple ways to list the names o...
A Semantic Model offers a deeper level of interpretation and insight of code compare to a syntax tree. Where syntax trees can tell the names of variables, semantic models also give the type and all references. Syntax trees notice method calls, but semantic models give references to the precise locat...

Page 1 of 1