Reputation: 13
We've developed in the past a code generation tool based on top of codedom to automate some code generation for our solution. The solution was parsing the full code tree to store custom information needed for our tool but I always found it quite a duplicate of what VS was already doing in the background. With the introduction of Roslyn I was expecting to have a better way to extract symbols definitions from the compiler, allowing me to query directly a solution symbols' table without requiring me to store custom data for our needs. We don't need to change the code in anyway, we just need to read the objects definitions like Classes, Specific methods, metadata and so on.
My question is, what is required to read those symbols? Do I need to parse again all projects/documents looking for those or is there an API which allows me to extract those symbols?
Upvotes: 0
Views: 708
Reputation: 887509
You're looking for the SymbolFinder
class, which you can use to find all references to a symbol within the SemanticModel for each project in the (MEF-imported) VisualStudioWorkspace.
Upvotes: 1
Reputation: 6420
You can register a symbol based action (with AnalysisContext.RegisterSymbolAction
), which gets called whenever a symbol is analyzed. But because you don't just want individual symbols, you'd probably be better off with registering a compilation start action, which internally would register a symbol action. This way, in the compilation end action you'd have all symbol info belonging to the whole project.
Upvotes: 1