Get exported semantic model for MetadataReference

孤街浪徒 提交于 2019-12-06 05:58:04

问题


Is it possible to get a collection of ITypeSymbol's for the types exported by an assembly that's been added to a compilation as a MetadataReference?

I want to inspect the types available to the referencing project.


回答1:


Call Compilation.GetAssemblyOrModuleSymbol() for each MetadataReference, cast to IAssemblySymbol, then look at the TypeNames property (which returns strings).

To get the actual ITypeSymbols for each type, fetch the assembly's GlobalNamespace, then recursively crawl through GetMembers() (which includes both types and nested namespaces). You can inherit a SymbolVisitor<IEnumerable<ITypeSymbol>> to help with the recursion (especially for nested types).



来源:https://stackoverflow.com/questions/32914240/get-exported-semantic-model-for-metadatareference

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