Example #1
0
        private static async Task <Document> ConvertFileScopedNamespaceAsync(Document document, CancellationToken cancellationToken)
        {
            var root = (CompilationUnitSyntax)await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            return(root.Members.OfType <FileScopedNamespaceDeclarationSyntax>().FirstOrDefault() is { } fileScopedNamespace
                ? await ConvertNamespaceTransform.ConvertFileScopedNamespaceAsync(document, fileScopedNamespace, cancellationToken).ConfigureAwait(false)
                : document);
        }
Example #2
0
        public async Task <Document> FormatNewDocumentAsync(Document document, Document?hintDocument, CodeCleanupOptions options, CancellationToken cancellationToken)
        {
            var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

            var root = (CompilationUnitSyntax)await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var namespaces = GetNamespacesToReplace(document, root, optionSet).ToList();

            if (namespaces.Count != 1)
            {
                return(document);
            }

            return(await ConvertNamespaceTransform.ConvertAsync(document, namespaces[0], options.FormattingOptions, cancellationToken).ConfigureAwait(false));
        }
Example #3
0
        public async Task <Document> FormatNewDocumentAsync(Document document, Document?hintDocument, CancellationToken cancellationToken)
        {
            var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

            var root = (CompilationUnitSyntax)await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var namespaces = GetNamespacesToReplace(document, root, optionSet);

            return(await document.ReplaceNodesAsync(namespaces, (oldNode, newNode) => ConvertNamespaceTransform.Convert((BaseNamespaceDeclarationSyntax)newNode), cancellationToken).ConfigureAwait(false));
        }