private static async Task<IEnumerable<NamespaceDeclaration>> GetNamespaceDeclarations(Project project)
{
var namespaceDeclarationTasks = project.Documents
.Select(document => new { document, codeFile = document.FilePath })
.Where(t => !IsGeneratedCodeFile(t.document, Patterns))
.Select(
async t =>
{
var collector = new NamespaceCollector();
var root = await t.document.GetSyntaxRootAsync().ConfigureAwait(false);
return new
{
t.codeFile,
namespaces = collector.GetNamespaces(root)
};
})
.Select(
async t =>
{
var result = await t.ConfigureAwait(false);
return result.namespaces
.Select(
x => new NamespaceDeclarationSyntaxInfo
{
Name = x.GetName(x.SyntaxTree.GetRoot()),
CodeFile = result.codeFile,
Syntax = x
});
});
var namespaceDeclarations = await Task.WhenAll(namespaceDeclarationTasks).ConfigureAwait(false);
return namespaceDeclarations
.SelectMany(x => x)
.GroupBy(x => x.Name)
.Select(y => new NamespaceDeclaration { Name = y.Key, SyntaxNodes = y });
}