This is a feature in Visual Studio, but academically I think you would collect using statements from your SyntaxTree like this:
var usings = syntaxTree.Root.DescendentNodes().Where(node is UsingDirectiveSyntax);
...and compare that to the namespaces resolved by the symbol table like this:
private static IEnumerable<INamespaceSymbol> GetNamespaceSymbol(ISymbol symbol)
{
if (symbol != null && symbol.ContainingNamespace != null)
yield return symbol.ContainingNamespace;
}
var ns = semanticModel.SyntaxTree.Root.DescendentNodes().SelectMany(node =>
GetNamespaceSymbol(semanticModel.GetSemanticInfo(node).Symbol)).Distinct();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…