I have a CSharpCompilation
instance containing an array of SyntaxTree
s and I am trying to find all the class declarations that inherit from a class
e.g
// Not in syntax tree but referenced in project
public class Base{}
// In syntax tree, how to find all such classes?
public class MyClass : Base {}
I've tried a few things but am a bit confused with all the options and can't seem to find the right way to do this.
I've tried to get the symbols but this doesn't work for inherited types
SyntaxTree[] trees = context.CSharpCompilation.SyntaxTrees;
IEnumerable<ISymbol> symbols = context.CSharpCompilation.GetSymbolsWithName(x => x == typeof(Base).Name, SymbolFilter.Type);
Quite new to Roslyn and would be most grateful for any suggestions or pointers for how to achieve this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…