9

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

enter image description here

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.

1 Answer 1

15

You can use the SemanticModel.GetDeclaredSymbol().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.