I use Roslyn to parse C # code. One of the things I need is to parse the node class declaration and get information about:
- Own base class
- Introduced Interfaces
I can access the declaration of the node (type ClassDeclarationSyntax
) class , and from there I can access BaseList
:
ClassDeclarationSyntax node = ...; // The class declaration
BaseListSyntax baseList = node.BaseList;
However, it BaseList
contains both interfaces and classes. I need to distinguish classes from interfaces. How?
Do I need to use SemanticModel
?
I searched the Roslyn Wiki and found that it was possible to access semantic information from my AST.
SyntaxTree programRoot = ...;
CSharpCompilation compilation = CSharpCompilation.Create("Program")
.AddReferences(MetadataReference.CreateFromFile(
typeof(object).Assembly.Location))
.AddSyntaxTrees(programRoot);
But how to get information from here? Thanks