I am trying to do something with nameof expressions in CSharpSyntaxWalker , however I noticed that AST does not have NameOfExpressionSyntax . Instead, I get InvocationExpressionSyntax , for which SemanticModel.GetSymbolInfo does not return matching characters, and the call expression is IdentifierNameSyntax containing the identifier token "nameof" .
So, in order to recognize nameof expressions, I would add a special case to VisitInvocationExpression , looking to see if GetSymbolInfo returns anything, and if not, then looking for the nameof identifier. However, this sounds a bit uncomfortable for me. Is there a better way, perhaps that transfers such detection logic to the parser?
(PS: I know this is probably being parsed, as it is for backward compatibility reasons, just wondering if an API exists to distinguish between nameof and regular calls.)
source share