Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class CustomSymbolFinder
{
public List<INamedTypeSymbol> GetAllSymbols(Compilation compilation)
{
var visitor = new FindAllSymbolsVisitor();
visitor.Visit(compilation.GlobalNamespace);
return visitor.AllTypeSymbols;
}
private class FindAllSymbolsVisitor : SymbolVisitor
{
public List<INamedTypeSymbol> AllTypeSymbols { get; } = new List<INamedTypeSymbol>();
public override void VisitNamespace(INamespaceSymbol symbol)
{
Parallel.ForEach(symbol.GetMembers(), s => s.Accept(this));
}
public override void VisitNamedType(INamedTypeSymbol symbol)
{
AllTypeSymbols.Add(symbol);
foreach (var childSymbol in symbol.GetTypeMembers())
{
base.Visit(childSymbol);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment