获取MetadataReference的导出语义模型 [英] Get exported semantic model for MetadataReference

查看:57
本文介绍了获取MetadataReference的导出语义模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取由程序集导出的类型的ITypeSymbol集合,该程序集已作为MetadataReference添加到编译中?

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.

推荐答案

为每个MetadataReference调用 Compilation.GetAssemblyOrModuleSymbol(),转换为 IAssemblySymbol ,然后查看 TypeNames 属性(返回字符串).

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

要获取每种类型的实际 ITypeSymbol ,请获取程序集的 GlobalNamespace ,然后递归地通过 GetMembers()进行爬网(包括两者类型和嵌套名称空间).您可以继承 SymbolVisitor< IEnumerable< ITypeSymbol>> 来帮助进行递归(尤其是对于嵌套类型).

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).

这篇关于获取MetadataReference的导出语义模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆