Beispiel #1
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

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

            CodeAction codeAction = CodeAction.Create(
                SplitVariableDeclarationRefactoring.GetTitle(variableDeclaration),
                cancellationToken => SplitVariableDeclarationRefactoring.RefactorAsync(context.Document, variableDeclaration, cancellationToken),
                DiagnosticIdentifiers.SplitVariableDeclaration + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Beispiel #2
0
        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out VariableDeclarationSyntax variableDeclaration))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                SplitVariableDeclarationRefactoring.GetTitle(variableDeclaration),
                cancellationToken => SplitVariableDeclarationRefactoring.RefactorAsync(context.Document, variableDeclaration, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.SplitVariableDeclaration));

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