Repository: dotnet/roslyn
File: src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.AddConstructorParametersCodeAction.cs (C#)

Code before:
            }
            else if (member is IFieldSymbol field)
            {
                foreach (var syntaxRef in field.DeclaringSyntaxReferences)
                {
                    var fieldSyntax = syntaxRef.GetSyntax(cancellationToken);
                    var fieldDocument = solution.GetRequiredDocument(fieldSyntax.SyntaxTree);
                    var fieldEditor = await solutionEditor.GetDocumentEditorAsync(fieldDocument.Id, cancellationToken).ConfigureAwait(false);

                    // Create the initializer expression using the parameter name
                    var initializerExpression = generator.IdentifierName(parameter.Name);
                    
                    // Add the initializer to the field - works for both C# and VB via WithInitializer
                    var newField = generator.WithInitializer(fieldSyntax, initializerExpression);

                    fieldEditor.ReplaceNode(fieldSyntax, newField);
                    break;
                }
            }
        }

        private static SyntaxNode? AddPropertyInitializerCSharp(SyntaxNode propertySyntax, string parameterName)
        {
            // Use duck typing to call C# syntax methods without a direct assembly reference
            // This works because we're checking the language is C# first
            var propertyType = propertySyntax.GetType();
            var withInitializerMethod = propertyType.GetMethod("WithInitializer");
            var withSemicolonTokenMethod = propertyType.GetMethod("WithSemicolonToken");
            
            if (withInitializerMethod != null && withSemicolonTokenMethod != null)
            {
                // Get the C# SyntaxFactory from the syntax node's assembly
                var syntaxFactoryType = propertySyntax.GetType().Assembly.GetType("Microsoft.CodeAnalysis.CSharp.SyntaxFactory");
                if (syntaxFactoryType != null)
                {
                    // Create IdentifierName(parameterName)
                    var identifierNameMethod = syntaxFactoryType.GetMethod("IdentifierName", new[] { typeof(string) });
                    var identifierName = identifierNameMethod?.Invoke(null, new object[] { parameterName });
                    
                    if (identifierName != null)
                    {
                        // Create EqualsValueClause
                        var expressionSyntaxType = propertySyntax.GetType().Assembly.GetType("Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax");
                        var equalsValueClauseMethod = syntaxFactoryType.GetMethod("EqualsValueClause", new[] { expressionSyntaxType! });
                        var equalsClause = equalsValueClauseMethod?.Invoke(null, new[] { identifierName });
                        
                        if (equalsClause != null)
                        {
                            // Get SemicolonToken
                            var tokenMethod = syntaxFactoryType.GetMethod("Token", new[] { propertySyntax.GetType().Assembly.GetType("Microsoft.CodeAnalysis.CSharp.SyntaxKind")! });
                            var syntaxKindType = propertySyntax.GetType().Assembly.GetType("Microsoft.CodeAnalysis.CSharp.SyntaxKind");

Review comment (refactor):
@copilot this si not acceptable.  We do not use reflection for things like this.  You can add a helper to SyntaxGeneratorInternal to do something like this instead. 

Code after:
        public override string Title
        {
            get
            {
                var parameters = Constructor.Parameters.Select(p => p.ToDisplayString(SimpleFormat));
                var parameterString = string.Join(", ", parameters);
                var signature = $"{this.Constructor.ContainingType.Name}({parameterString})";

                if (_useSubMenuName)
                    return string.Format(CodeFixesResources.Add_to_0, signature);

                return MissingParameters[0].parameter.IsOptional
                    ? string.Format(FeaturesResources.Add_optional_parameters_to_0, signature)
                    : string.Format(FeaturesResources.Add_parameters_to_0, signature);
            }
        }

        /// <summary>
        /// A metadata name used by telemetry to distinguish between the different kinds of this code action.
        /// This code action will perform 2 different actions depending on if missing parameters can be optional.
        /// 
        /// In this case we don't want to use the title as it depends on the class name for the ctor.
        /// </summary>
        internal string ActionName => MissingParameters[0].parameter.IsOptional
            ? nameof(FeaturesResources.Add_optional_parameters_to_0)
            : nameof(FeaturesResources.Add_parameters_to_0);
    }
}