I'm currently trying to define a code fix with Roslyn. I have a SyntaxNode
variable.
I would like to find all references of that variable at my DiagnosticAnalyzer
class. Unfortunately SymbolFinder.FindReferencesAsync
method requires a Solution
parameter, and if I know well, I can't get the current solution from DiagnosticAnalyzer
class.
How can I get all references of a variable at DiagnosticAnalyzer
class?
I implemented a similar Analyzer, the algorithm was the following (it ran for ~31ms on a 2000+ line Document, but almost always under 10 ms)
SemanticModel.GetRoot()
and collect Expressions and LocalDeclarations IDisposable
, store in HashSet1
if it does HashSet2
SyntaxReference
of Symbols that are in HashSet1
but not in HashSet2
This works well, but sadly I do not know if there is a more efficient / cleaner way of doing this. I can share parts of the code if you like.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.