예제 #1
0
        public static async Task AddMissingNamespacesAsync(this DocumentEditor editor, NamespaceSet namespaces,
                                                           Compilation compilation, INamespaceSymbol containingNamespace, SyntaxTree syntaxTree, SemanticModel semanticModel, CancellationToken ct)
        {
            namespaces = new NamespaceSet(namespaces); // Make a copy because namespaces is a input parameter

            namespaces.ExceptWith(containingNamespace.GetImplicitlyImportedNamespaces());
            if (namespaces.Count == 0)
            {
                return;
            }

            var globalImports = compilation.GetGlobalImports().ToArray();

            if (globalImports.Length > 0)
            {
                namespaces.RemoveWhere(x => globalImports.Contains(x.ToDisplayString()));
            }

            var importedNamespaces = ImportedNamespace.GetImportedNamespaces(syntaxTree, semanticModel);
            await editor.AddMissingNamespaces(namespaces, importedNamespaces, ImportedNamespace.GetAddFunc(semanticModel.Language), ct);
        }