Пример #1
0
        private static CompilationUnitSyntax SortUsingDirectives(
            this CompilationUnitSyntax compilation,
            ref NamespaceDeclarationSyntax ns)
        {
            // TODO: Add removing of unused namespaces
            var usings = compilation
                         .GetAllUsingDirectives(ns)
                         .OrderBy(u => u, UsingsAndExternAliasesDirectiveComparer.SystemFirstInstance)
                         .ToSyntaxList();

            compilation = compilation.RemoveAllUsings(ref ns);

            if (ns != null)
            {
                var newNs = ns.WithUsings(usings);

                compilation = compilation.ReplaceNode(ns, newNs);
                ns          = newNs;
            }
            else
            {
                compilation = compilation.WithUsings(usings);
            }

            return(compilation);
        }