public static async Task ComputeRefactoringsAsync(RefactoringContext context, InitializerExpressionSyntax initializer)
        {
            if (!initializer.IsKind(
                    SyntaxKind.ObjectInitializerExpression,
                    SyntaxKind.CollectionInitializerExpression))
            {
                return;
            }

            if (!initializer.Expressions.Any())
            {
                return;
            }

            SyntaxNode parent = initializer.Parent;

            if (parent?.Kind() != SyntaxKind.ObjectCreationExpression)
            {
                return;
            }

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

            if (!CanExpand(initializer, semanticModel, context.CancellationToken))
            {
                return;
            }

            if (parent.IsParentKind(SyntaxKind.SimpleAssignmentExpression))
            {
                SimpleAssignmentStatementInfo simpleAssignment = SyntaxInfo.SimpleAssignmentStatementInfo((AssignmentExpressionSyntax)parent.Parent);

                if (simpleAssignment.Success)
                {
                    RegisterRefactoring(context, simpleAssignment.Statement, initializer, simpleAssignment.Left);
                }
            }
            else
            {
                LocalDeclarationStatementInfo localInfo = SyntaxInfo.LocalDeclarationStatementInfo((ExpressionSyntax)parent);

                if (localInfo.Success)
                {
                    var declarator = (VariableDeclaratorSyntax)parent.Parent.Parent;

                    RegisterRefactoring(
                        context,
                        localInfo.Statement,
                        initializer,
                        IdentifierName(declarator.Identifier.ValueText));
                }
            }
        }
        public static void AnalyzeLocalDeclarationStatement(SyntaxNodeAnalysisContext context)
        {
            if (context.Node.ContainsDiagnostics)
            {
                return;
            }

            var localDeclaration = (LocalDeclarationStatementSyntax)context.Node;

            if (localDeclaration.IsConst)
            {
                return;
            }

            StatementListInfo statementsInfo = SyntaxInfo.StatementListInfo(localDeclaration);

            if (!statementsInfo.Success)
            {
                return;
            }

            SyntaxList <StatementSyntax> statements = statementsInfo.Statements;

            if (statements.Count <= 1)
            {
                return;
            }

            int index = statements.IndexOf(localDeclaration);

            if (index == statements.Count - 1)
            {
                return;
            }

            LocalDeclarationStatementInfo localInfo = SyntaxInfo.LocalDeclarationStatementInfo(localDeclaration);

            if (!localInfo.Success)
            {
                return;
            }

            ITypeSymbol typeSymbol = context.SemanticModel.GetTypeSymbol(localInfo.Type, context.CancellationToken);

            if (typeSymbol?.SupportsConstantValue() != true)
            {
                return;
            }

            if (localInfo.Type.IsVar && !typeSymbol.SupportsExplicitDeclaration())
            {
                return;
            }

            foreach (VariableDeclaratorSyntax declarator in localInfo.Variables)
            {
                if (!HasConstantValue(declarator.Initializer?.Value, typeSymbol, context.SemanticModel, context.CancellationToken))
                {
                    return;
                }
            }

            if (!CanBeMarkedAsConst(localInfo.Variables, statements, index + 1))
            {
                return;
            }

            DiagnosticHelpers.ReportDiagnostic(context, DiagnosticDescriptors.MarkLocalVariableAsConst, localInfo.Type);
        }
        private static void AnalyzeLocalDeclarationStatement(SyntaxNodeAnalysisContext context)
        {
            if (context.Node.ContainsDiagnostics)
            {
                return;
            }

            var localDeclaration = (LocalDeclarationStatementSyntax)context.Node;

            if (localDeclaration.IsConst)
            {
                return;
            }

            StatementListInfo statementsInfo = SyntaxInfo.StatementListInfo(localDeclaration);

            if (!statementsInfo.Success)
            {
                return;
            }

            SyntaxList <StatementSyntax> statements = statementsInfo.Statements;

            if (statements.Count <= 1)
            {
                return;
            }

            int index = statements.IndexOf(localDeclaration);

            if (index == statements.Count - 1)
            {
                return;
            }

            LocalDeclarationStatementInfo localInfo = SyntaxInfo.LocalDeclarationStatementInfo(localDeclaration);

            if (!localInfo.Success)
            {
                return;
            }

            ITypeSymbol typeSymbol = context.SemanticModel.GetTypeSymbol(localInfo.Type, context.CancellationToken);

            if (typeSymbol?.SupportsConstantValue() != true)
            {
                return;
            }

            if (localInfo.Type.IsVar && !typeSymbol.SupportsExplicitDeclaration())
            {
                return;
            }

            foreach (VariableDeclaratorSyntax declarator in localInfo.Variables)
            {
                ExpressionSyntax value = declarator.Initializer?.Value?.WalkDownParentheses();

                if (value?.IsMissing != false)
                {
                    return;
                }

                if (!HasConstantValue(value, typeSymbol, context.SemanticModel, context.CancellationToken))
                {
                    return;
                }
            }

            if (!CanBeMarkedAsConst(localInfo.Variables, statements, index + 1))
            {
                return;
            }

            if (((CSharpParseOptions)context.Node.SyntaxTree.Options).LanguageVersion <= LanguageVersion.CSharp9 &&
                ContainsInterpolatedString(localInfo.Variables))
            {
                return;
            }

            DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.MarkLocalVariableAsConst, localInfo.Type);
        }