Example #1
0
        private static async Task <Document> AddUsingsToDocument(Document document)
        {
            var newSyntaxRoot = await document.GetSyntaxRootAsync();

            newSyntaxRoot = UsingHandler.AddUsingIfNotExists(newSyntaxRoot, TaskUsing);
            return(document.WithSyntaxRoot(newSyntaxRoot));
        }
        private async Task <Document> ReplaceThreadWithTask(Document document, SyntaxNode node,
                                                            CancellationToken cancellationToken)
        {
            var root = await document.GetSyntaxRootAsync(cancellationToken);

            var argument            = node.DescendantNodes().OfType <ArgumentSyntax>().First();
            var invocationStatement = TaskSyntaxHelper.CreateInvocationStatement(argument);

            var newRoot = root.ReplaceNode(node, invocationStatement);

            newRoot = UsingHandler.AddUsingIfNotExists(newRoot, TaskUsing);
            var newDocument = document.WithSyntaxRoot(newRoot);

            return(newDocument);
        }