How can I get class semantic model (ITypeSymbol
) from ClassDeclarationSyntax
in Roslyn? From this syntax tree:
it seems to me that the only point I can use is ClassDeclaration
as tokens like IdentifierToken
cannot be passed to the GetSymbolInfo
method. But when I write
context.SemanticModel.GetSymbolInfo(classDeclaration)
the result is
context.SemanticModel.GetSymbolInfo(classDeclaration)
{Microsoft.CodeAnalysis.SymbolInfo}
CandidateReason: None
CandidateSymbols: Length = 0
IsEmpty: true
Symbol: null
_candidateSymbols: Length = 0
... so no match. I wonder if the problem is that I am asking for wrong syntax element, or the issue is in fact I am asking in the moment I analyze attribute of the class and the class itself is not yet prepared.
You can use the SemanticModel.GetDeclaredSymbol()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With