private Task <Document> ChangeReturnTypeToTask(CodeFixContext context, SyntaxNode root, MethodDeclarationSyntax methodDeclaration)
        {
            var newReturnType        = SyntaxFactory.IdentifierName("Task");
            var newMethodDeclaration = methodDeclaration.WithReturnType(newReturnType);

            return(context.GetDocumentWithReplacedNode(methodDeclaration, newMethodDeclaration, root));
        }
Exemple #2
0
        private Task <Document> MergeSwitchStatements(
            CodeFixContext context,
            SyntaxNode root,
            SwitchStatementSyntax switchStatement)
        {
            var newSwitchStatement = switchStatement.MergeSwitchStatementsWithEquivalentContent();

            return(context.GetDocumentWithReplacedNode(switchStatement, newSwitchStatement, root));
        }
Exemple #3
0
        private Task <Document> AddSealedModifierToClass(
            CodeFixContext context,
            SyntaxNode root,
            ClassDeclarationSyntax classDeclaration)
        {
            var syntaxGenerator     = SyntaxGenerator.GetGenerator(context.Document);
            var newClassDeclaration = syntaxGenerator.WithModifiers(classDeclaration, DeclarationModifiers.Sealed);

            return(context.GetDocumentWithReplacedNode(classDeclaration, newClassDeclaration, root));
        }
        private Task <Document> MoveDefaultLabelToLastInSwitchStatement(
            CodeFixContext context,
            SyntaxNode root,
            SwitchStatementSyntax
            switchStatement)
        {
            var newSwitchStatement = switchStatement.MoveDefaultSwitchSectionToLastInSwitchStatement();

            newSwitchStatement = newSwitchStatement.MoveDefaultLabelToLastInSwitchSection();
            return(context.GetDocumentWithReplacedNode(switchStatement, newSwitchStatement, root));
        }
        private Task <Document> AddConfigureAwaitFalse(
            CodeFixContext context,
            SyntaxNode root,
            AwaitExpressionSyntax awaitExpression)
        {
            var invocation      = (InvocationExpressionSyntax)awaitExpression.Expression;
            var syntaxGenerator = SyntaxGenerator.GetGenerator(context.Document);

            var memberAccessExpression = syntaxGenerator.MemberAccessExpression(invocation.WithTrailingTrivia(), syntaxGenerator.IdentifierName("ConfigureAwait"));
            var argument      = syntaxGenerator.Argument(syntaxGenerator.FalseLiteralExpression());
            var newInvocation = syntaxGenerator.InvocationExpression(memberAccessExpression, argument) as InvocationExpressionSyntax;

            var newAwaitExpression = awaitExpression.WithExpression(newInvocation);

            return(context.GetDocumentWithReplacedNode(awaitExpression, newAwaitExpression, root));
        }