Пример #1
0
        private static async Task <SyntaxNode> CreateNewDocumentSyntaxRootAsync(FixAllContext fixAllContext, Document document, CancellationToken cancellationToken)
        {
            var diagnostics = await fixAllContext.GetDocumentDiagnosticsAsync(document).ConfigureAwait(false);

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

            var nodesToFix = diagnostics.Select(diagnostic => DefaulIfNullExpressionHelper.GetTargetExpression(diagnostic, root));

            return(root.ReplaceNodes(nodesToFix,
                                     (orignalNode, rewritten) => DefaulIfNullExpressionHelper.CreateRelacementNode(rewritten)));
        }
        private static async Task <Document> CreateChangedDocument(CodeFixContext codeFixContext, CancellationToken cancellationToken)
        {
            var document   = codeFixContext.Document;
            var diagnostic = codeFixContext.Diagnostics.First();

            var root = await document.GetSyntaxRootAsync(cancellationToken);

            var invocationExpression = DefaulIfNullExpressionHelper.GetTargetExpression(diagnostic, root);
            var replacement          = DefaulIfNullExpressionHelper.CreateRelacementNode(invocationExpression);
            var newRoot = root.ReplaceNode(invocationExpression, replacement);

            return(document.WithSyntaxRoot(newRoot));
        }