(Please note: This is not about run-time reflection/metainfo)
I am writing a concrete implementation of Roslyn CSharpSyntaxVisitor
When implementing the VisitIdentifierName
public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax name)
{
var symbolInfo = _semanticModel.GetSymbolInfo(name);
var fieldSymbol = symbolInfo.Symbol as IFieldSymbol;
if (fieldSymbol != null)
{
// Here I would like to get all the local variable names what are visible
// in the very same scope where this field IdentifierNameSyntax under visiting resides
// We can suppose that _semanticNodel for the Document is available.
}
}
Call SemanticModel.LookupSymbols()
(source), then filter for local variables.
You may also want to filter out locals declared after that location; see this code.
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