/// <summary> /// Applies the attribute to all members in the document. /// </summary> public async Task <Document> ProcessAsync(Document document, CancellationToken cancellationToken = default(CancellationToken)) { var syntax = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); syntax = new VisualBasicRewriteVisitor(SyntaxGenerator.GetGenerator(document)).Visit(syntax); return(document.WithSyntaxRoot(syntax)); }
/// <summary> /// Removes and sorts namespaces. /// </summary> public async Task <Document> ProcessAsync(Document document, CancellationToken cancellationToken = default) { // This codefix is available for both C# and VB //document = await document.ApplyCodeFixAsync(CodeFixNames.All.RemoveUnnecessaryImports); var generator = SyntaxGenerator.GetGenerator(document); var syntax = await document.GetSyntaxRootAsync(); var imports = generator.GetNamespaceImports(syntax).Select(generator.GetName).ToArray(); Array.Sort(imports); if (document.Project.Language == LanguageNames.CSharp) { syntax = new CSharpRewriteVisitor().Visit(syntax); } else { syntax = new VisualBasicRewriteVisitor().Visit(syntax); } return(document.WithSyntaxRoot(generator.AddNamespaceImports(syntax, imports.Select(generator.NamespaceImportDeclaration)))); }