问题
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