Exemplo n.º 1
0
        private void AnalyzeCatchClause(SyntaxNodeAnalysisContext context)
        {
            var catchClause = (CatchClauseSyntax)context.Node;

            RemoveOriginalExceptionFromThrowStatementRefactoring.Analyze(context, catchClause);

            AvoidEmptyCatchClauseThatCatchesSystemExceptionRefactoring.Analyze(context, catchClause);
        }
Exemplo n.º 2
0
        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out ThrowStatementSyntax throwStatement))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove original exception from throw statement",
                cancellationToken => RemoveOriginalExceptionFromThrowStatementRefactoring.RefactorAsync(context.Document, throwStatement, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.RemoveOriginalExceptionFromThrowStatement));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Exemplo n.º 3
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            ThrowStatementSyntax throwStatement = root
                                                  .FindNode(context.Span, getInnermostNodeForTie: true)?
                                                  .FirstAncestorOrSelf <ThrowStatementSyntax>();

            if (throwStatement == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove original exception from throw statement",
                cancellationToken => RemoveOriginalExceptionFromThrowStatementRefactoring.RefactorAsync(context.Document, throwStatement, cancellationToken),
                DiagnosticIdentifiers.RemoveOriginalExceptionFromThrowStatement + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }