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

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out AssignmentExpressionSyntax assignment))
            {
                return;
            }

            foreach (Diagnostic diagnostic in context.Diagnostics)
            {
                switch (diagnostic.Id)
                {
                case DiagnosticIdentifiers.UseCompoundAssignment:
                {
                    var binaryExpression = (BinaryExpressionSyntax)assignment.Right;

                    string operatorText = UseCompoundAssignmentRefactoring.GetCompoundOperatorText(binaryExpression);

                    CodeAction codeAction = CodeAction.Create(
                        $"Use {operatorText} operator",
                        cancellationToken => UseCompoundAssignmentRefactoring.RefactorAsync(context.Document, assignment, cancellationToken),
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }

                case DiagnosticIdentifiers.UsePostfixUnaryOperatorInsteadOfAssignment:
                {
                    string operatorText = UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.GetOperatorText(assignment);

                    CodeAction codeAction = CodeAction.Create(
                        $"Use {operatorText} operator",
                        c => UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.RefactorAsync(context.Document, assignment, c),
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }

                case DiagnosticIdentifiers.RemoveRedundantDelegateCreation:
                {
                    CodeAction codeAction = CodeAction.Create(
                        "Remove redundant delegate creation",
                        cancellationToken =>
                        {
                            return(RemoveRedundantDelegateCreationRefactoring.RefactorAsync(
                                       context.Document,
                                       (ObjectCreationExpressionSyntax)assignment.Right,
                                       cancellationToken));
                        },
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }
                }
            }
        }
        private void AnalyzeSimpleAssignment(SyntaxNodeAnalysisContext context)
        {
            var assignment = (AssignmentExpressionSyntax)context.Node;

            if (UseCompoundAssignmentRefactoring.CanRefactor(assignment))
            {
                var binaryExpression = (BinaryExpressionSyntax)assignment.Right;

                context.ReportDiagnostic(DiagnosticDescriptors.UseCompoundAssignment, assignment, UseCompoundAssignmentRefactoring.GetCompoundOperatorText(binaryExpression));
                context.ReportNode(DiagnosticDescriptors.UseCompoundAssignmentFadeOut, binaryExpression.Left);
            }
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

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

            if (assignment == null)
            {
                return;
            }

            foreach (Diagnostic diagnostic in context.Diagnostics)
            {
                switch (diagnostic.Id)
                {
                case DiagnosticIdentifiers.UseCompoundAssignment:
                {
                    var binaryExpression = (BinaryExpressionSyntax)assignment.Right;

                    string operatorText = UseCompoundAssignmentRefactoring.GetCompoundOperatorText(binaryExpression);

                    CodeAction codeAction = CodeAction.Create(
                        $"Use {operatorText} operator",
                        cancellationToken => UseCompoundAssignmentRefactoring.RefactorAsync(context.Document, assignment, cancellationToken),
                        diagnostic.Id + EquivalenceKeySuffix);

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }

                case DiagnosticIdentifiers.UsePostfixUnaryOperatorInsteadOfAssignment:
                {
                    SyntaxKind kind = UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.GetPostfixUnaryOperatorKind(assignment);

                    string operatorText = UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.GetOperatorText(kind);

                    CodeAction codeAction = CodeAction.Create(
                        $"Use {operatorText} operator",
                        c => UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.RefactorAsync(context.Document, assignment, kind, c),
                        diagnostic.Id + EquivalenceKeySuffix);

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }

                case DiagnosticIdentifiers.RemoveRedundantDelegateCreation:
                {
                    CodeAction codeAction = CodeAction.Create(
                        "Remove redundant delegate creation",
                        cancellationToken =>
                        {
                            return(RemoveRedundantDelegateCreationRefactoring.RefactorAsync(
                                       context.Document,
                                       (ObjectCreationExpressionSyntax)assignment.Right,
                                       cancellationToken));
                        },
                        diagnostic.Id + EquivalenceKeySuffix);

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }
                }
            }
        }