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 AnalyzeAssignmentExpression(SyntaxNodeAnalysisContext context)
        {
            if (GeneratedCodeAnalyzer?.IsGeneratedCode(context) == true)
            {
                return;
            }

            var assignment = (AssignmentExpressionSyntax)context.Node;

            ExpressionSyntax left  = assignment.Left;
            ExpressionSyntax right = assignment.Right;

            if (left?.IsMissing == false &&
                right?.IsNumericLiteralExpression(1) == true)
            {
                ITypeSymbol typeSymbol = context.SemanticModel.GetTypeInfo(left, context.CancellationToken).Type;

                if (typeSymbol?.SupportsPrefixOrPostfixUnaryOperator() == true &&
                    !assignment.SpanContainsDirectives())
                {
                    context.ReportDiagnostic(
                        DiagnosticDescriptors.UsePostfixUnaryOperatorInsteadOfAssignment,
                        assignment.GetLocation(),
                        UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.GetOperatorText(assignment));
                }
            }

            RemoveRedundantDelegateCreationRefactoring.Analyze(context, assignment);
        }
        private void AnalyzeAssignmentExpression(SyntaxNodeAnalysisContext context)
        {
            var assignment = (AssignmentExpressionSyntax)context.Node;

            UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.Analyze(context, assignment);

            RemoveRedundantDelegateCreationRefactoring.Analyze(context, assignment);
        }
        private void AnalyzeAssignmentExpression(SyntaxNodeAnalysisContext context)
        {
            var assignment = (AssignmentExpressionSyntax)context.Node;

            RemoveRedundantDelegateCreationRefactoring.Analyze(context, assignment);
        }
        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.SimplifyAssignmentExpression:
                {
                    CodeAction codeAction = CodeAction.Create(
                        "Simplify assignment expression",
                        cancellationToken =>
                        {
                            return(SimplifyAssignmentExpressionRefactoring.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",
                        cancellationToken =>
                        {
                            return(UsePostfixUnaryOperatorInsteadOfAssignmentRefactoring.RefactorAsync(
                                       context.Document,
                                       assignment,
                                       kind,
                                       cancellationToken));
                        },
                        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;
                }
                }
            }
        }