Monday, October 31, 2011 10:03 PM
How does one have to navigate the object model to go from an ISolution object in order to do something like a "Find All references" across multiple projects? For example, say I have an ISolution object called "solution" that has 20 projects. One of which has a type called "TypeImSearchingFor". I would like to know how to iterate/scan all the projects of that solution to find a reference back to the TypeImSearchingFor.
I would think we have to get a compilation unit of the entire solution in order to navigate the semantic model and search for the symbol for "TypeImSearchingFor" but I can't find a way to get a compilation unit for the entire solution. Or even for the entire project of any particular individual project.
In other words, how can I take this example : http://social.msdn.microsoft.com/Forums/en-US/roslyn/thread/85a816cb-e931-4b49-893a-abbbf38c7a38 and scale it to search for a type (or method of a type) in a list of projects loaded into a solution?
Monday, October 31, 2011 11:04 PMOwner
Hi Mark - If you already have a Roslyn.Services.ISolution, then you should be able to iterate all projects underneath this solution using the ISolution.Projects property. Subsequently you can iterate all documents under each project by invoking the IProject.Documents property. You can then access the SyntaxTree, SemanticModel, Compilation for the document to do something similar to the other post you pointed to.
To get the Compilation for any IProject, you can simply invoke IProject.GetCompilation(). The Compilation is also accessible from the SemanticModel for any Document / SyntaxTree.
If you don't have a Roslyn.Services.ISolution, you can use the Roslyn Workspaces API to get one as shown above. You will need to add reference to Roslyn.Services.dll which should be present under C:\Program Files (x86)\Reference Assemblies\Microsoft\Roslyn\v1.0\...
Hope this helps!
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team
- Edited by Shyam NamboodiripadMicrosoft Employee, Owner Monday, October 31, 2011 11:21 PM
- Edited by Shyam NamboodiripadMicrosoft Employee, Owner Monday, October 31, 2011 11:28 PM
- Proposed As Answer by Shyam NamboodiripadMicrosoft Employee, Owner Tuesday, November 01, 2011 7:21 PM
- Marked As Answer by Karen Ng MSFTOwner Wednesday, November 02, 2011 12:52 AM
Tuesday, November 01, 2011 12:18 AMOwnerThere is a Find All References service that you can access from a Roslyn Visual Studio extension. Just MEF-import an IFindReferencesService from a Roslyn VS, such as a Code Issue project. We are planning to move this service down into the Roslyn.Services layer so that it can be used at the command-line, but we weren't able to complete that for the CTP. Once that API is in place, you won't need to iterate the ISolution model to find references to types, methods or other symbols.
Dustin Campbell | Senior Program Manager | Roslyn Visual Basic and C# Language Services