I am using Roslyn to analyze C# code. One of the things I need to have is analyzing a class declaration node and get information about:
- Its base class
- Its implemented interfaces
I can get access to the class declaration node (type ClassDeclarationSyntax
), and from there I can get access to the BaseList
:
ClassDeclarationSyntax node = ...; // The class declaration
BaseListSyntax baseList = node.BaseList;
However baseList
contains both interfaces and classes. I need ti distinguish classes from interfaces. How?
Do I need to use the SemanticModel
?
I've searched Roslyn's Wiki and discovered that it is possible to access semantic information from my AST.
SyntaxTree programRoot = ...; // Getting the AST root
CSharpCompilation compilation = CSharpCompilation.Create("Program")
.AddReferences(MetadataReference.CreateFromFile(
typeof(object).Assembly.Location))
.AddSyntaxTrees(programRoot);
But how to get those info from here? Thanks