コード例 #1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, SyntaxToken token)
        {
            SyntaxNode parent = token.Parent;

            switch (parent.Kind())
            {
            case SyntaxKind.MethodDeclaration:
            {
                var methodDeclaration = (MethodDeclarationSyntax)parent;

                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(methodDeclaration, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case SyntaxKind.LocalFunctionStatement:
            {
                var localFunction = (LocalFunctionStatementSyntax)parent;

                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(localFunction, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case SyntaxKind.ParenthesizedLambdaExpression:
            {
                var parenthesizedLambda = (ParenthesizedLambdaExpressionSyntax)parent;

                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(parenthesizedLambda, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case SyntaxKind.SimpleLambdaExpression:
            {
                var simpleLambda = (SimpleLambdaExpressionSyntax)parent;

                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(simpleLambda, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case SyntaxKind.AnonymousMethodExpression:
            {
                var anonymousMethod = (AnonymousMethodExpressionSyntax)parent;

                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(anonymousMethod, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }
            }
        }
コード例 #2
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, SyntaxToken token)
        {
            switch (token.Parent)
            {
            case MethodDeclarationSyntax methodDeclaration:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(methodDeclaration, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case LocalFunctionStatementSyntax localFunction:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(localFunction, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case ParenthesizedLambdaExpressionSyntax parenthesizedLambda:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(parenthesizedLambda, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case SimpleLambdaExpressionSyntax simpleLambda:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(simpleLambda, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }

            case AnonymousMethodExpressionSyntax anonymousMethod:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(anonymousMethod, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    RegisterRefactoring(context, token, analysis);
                }

                return;
            }
            }
        }
コード例 #3
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, SyntaxToken token)
        {
            switch (token.Parent)
            {
            case MethodDeclarationSyntax methodDeclaration:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                using (RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(methodDeclaration, semanticModel, context.CancellationToken))
                {
                    if (analysis.Success)
                    {
                        RegisterRefactoring();
                    }
                }

                return;
            }

            case LocalFunctionStatementSyntax localFunction:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                using (RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(localFunction, semanticModel, context.CancellationToken))
                {
                    if (analysis.Success)
                    {
                        RegisterRefactoring();
                    }
                }

                return;
            }

            case ParenthesizedLambdaExpressionSyntax parenthesizedLambda:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                using (RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(parenthesizedLambda, semanticModel, context.CancellationToken))
                {
                    if (analysis.Success)
                    {
                        RegisterRefactoring();
                    }
                }

                return;
            }

            case SimpleLambdaExpressionSyntax simpleLambda:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                using (RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(simpleLambda, semanticModel, context.CancellationToken))
                {
                    if (analysis.Success)
                    {
                        RegisterRefactoring();
                    }
                }

                return;
            }

            case AnonymousMethodExpressionSyntax anonymousMethod:
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                using (RemoveAsyncAwaitAnalysis analysis = RemoveAsyncAwaitAnalysis.Create(anonymousMethod, semanticModel, context.CancellationToken))
                {
                    if (analysis.Success)
                    {
                        RegisterRefactoring();
                    }
                }

                return;
            }
            }

            void RegisterRefactoring()
            {
                CodeAction codeAction = CodeActionFactory.RemoveAsyncAwait(context.Document, token, equivalenceKey: EquivalenceKey.Create(RefactoringDescriptors.RemoveAsyncAwait));

                context.RegisterRefactoring(codeAction);
            }
        }