Closed
Description
I've been trying this for about 45 minutes now, but I can't seem to figure out how to get a list of all of the INamedTypeSymbol
available in a given compilation. I tried digging through the Compilation.GetTypeByMetadataName
stuff, but couldn't figure it out.
I tried using Compilation.GlobalNamespace.GetTypeMembers()
and it seems to give me all the IModuleSymbols
that are referenced by the current project. (I see mscorlib, System.Core etc.) I then tried getting the type members inside these modules, but they were either empty or contained PrivateImplementation
stuff.
Is there an API to get access to all the INamedTypeSymbols
available in a compilation?
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
SLaks commentedon Oct 19, 2015
You need to recurse through all of the namespaces in the global namespace
daveaglick commentedon Oct 19, 2015
Yep - I've found the easiest way to do the recursion is with a
SymbolVisitor
:SLaks commentedon Oct 19, 2015
@daveaglick You can syntax-highlight that code by wrapping it in
SLaks commentedon Oct 19, 2015
See also http://stackoverflow.com/a/32937808/34397
daveaglick commentedon Oct 19, 2015
@SLaks Holy cow - I had no idea I could force language highlighting. One of those simple little things I never picked up...thanks!
SLaks commentedon Oct 19, 2015
Also, your visitor won't catch nested types.
daveaglick commentedon Oct 19, 2015
Yeah, just left that out - there's actually a pretty full example here that does:
https://github.com/Wyamio/Wyam/blob/develop/Wyam.Modules.CodeAnalysis/AnalyzeSymbolVisitor.cs
JoshVarty commentedon Oct 19, 2015
Thanks guys, that should be more than enough to get me started. :)
drewnoakes commentedon Sep 19, 2016
@daveaglick that link's broken. I believe it is now:
https://github.com/Wyamio/Wyam/blob/develop/src/Wyam.CodeAnalysis/AnalyzeSymbolVisitor.cs
daveaglick commentedon Sep 19, 2016
@drewnoakes Indeed it is! A casualty of refactoring, thanks for updating it.
aodl commentedon Jun 25, 2019
@daveaglick that link's broken. I believe it is now:
https://github.com/Wyamio/Wyam/blob/develop/src/extensions/Wyam.CodeAnalysis/Analysis/AnalyzeSymbolVisitor.cs
:)
daveaglick commentedon Jun 25, 2019
...and that link will probably break soon too! Here’s one that’s pegged to a specific commit so it should be evergreen:
https://github.com/statiqdev/Framework/blob/76e2d2bda014353478ae65ef179f55180b432b94/src/extensions/Statiq.CodeAnalysis/Analysis/AnalyzeSymbolVisitor.cs
kentcb commentedon May 10, 2020
Hmm, maybe I'm missing something, but I did this:
Now trying to evaluate whether a visitor is cleaner/better.