How to GetSemanticModel for any syntax tree in referenced projects of project compilation

时光怂恿深爱的人放手 提交于 2019-12-08 14:15:31

You have to call GetSemanticModel for the compilation that contains that tree. So if project A depends on B, and you've walked over to a Syntax Tree in B, you have to use the compilation for B to ask about B. That's because A doesn't actually "know" about anything in B per se, it's an opaque box.

Your best opportunity is probably to use the workspace API more. When you called OpenProjectAsync(), grab the Solution object from the .Solution property. From there you can walk across all the projects more directly, and if you have a tree you can also do Solution.GetDocument(tree).GetSemanticModelAsync().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!