How to get the semantic model of a class from the class syntax tree?

How can I get the semantic class model ( ITypeSymbol) from ClassDeclarationSyntaxin Roslyn? From this syntax tree:

enter image description here

It seems to me that the only point I can use is ClassDeclarationbecause the tokens seem IdentifierTokento be unable to be passed to the method GetSymbolInfo. But when I write

context.SemanticModel.GetSymbolInfo(classDeclaration)

result

context.SemanticModel.GetSymbolInfo(classDeclaration)
{Microsoft.CodeAnalysis.SymbolInfo}
    CandidateReason: None
    CandidateSymbols: Length = 0
    IsEmpty: true
    Symbol: null
    _candidateSymbols: Length = 0

... Then no. Interestingly, the problem is that I am setting the wrong syntax element, or the problem I actually ask at the moment when I analyze the attribute of the class, and the class itself is not yet prepared.

+4
source share
1 answer

You can use SemanticModel.GetDeclaredSymbol().

+6

Source: https://habr.com/ru/post/1613856/


All Articles