Repository: dotnet/roslyn
File: src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs (C#)

Code before:
                case SyntaxKind.EventDeclaration:
                    var ev = (EventDeclarationSyntax)member;
                    return this.EventDeclaration(
                        ev.Identifier.ValueText,
                        ev.Type,
                        Accessibility.NotApplicable,
                        DeclarationModifiers.None);

                case SyntaxKind.EventFieldDeclaration:
                    var ef = (EventFieldDeclarationSyntax)member;
                    return ef.WithModifiers(default);

                // convert field into property
                case SyntaxKind.FieldDeclaration:
                    var f = (FieldDeclarationSyntax)member;
                    GetAccessibilityAndModifiers(f.Modifiers, out acc, out modifiers, out _);

                    var type = GetType(f);
                    Contract.ThrowIfNull(type);

                    return AsInterfaceMember(
                        PropertyDeclaration(GetName(f), ClearTrivia(type), acc, modifiers, getAccessorStatements: null, setAccessorStatements: null));

                case SyntaxKind.DelegateDeclaration:
                    var delegateDecl = (DelegateDeclarationSyntax)member;
                    return delegateDecl.WithModifiers(default);

                default:
                    throw ExceptionUtilities.UnexpectedValue(member.Kind());
            }
        });
    }

    public override SyntaxNode EnumDeclaration(
        string name,
        Accessibility accessibility,
        DeclarationModifiers modifiers,
        IEnumerable<SyntaxNode>? members)
    {
        return EnumDeclaration(name, underlyingType: null, accessibility, modifiers, members);
    }

    internal override SyntaxNode EnumDeclaration(string name, SyntaxNode? underlyingType, Accessibility accessibility = Accessibility.NotApplicable, DeclarationModifiers modifiers = default, IEnumerable<SyntaxNode>? members = null)
    {
        return SyntaxFactory.EnumDeclaration(
            default,
            AsModifierList(accessibility, modifiers, SyntaxKind.EnumDeclaration),
            name.ToIdentifierToken(),
            underlyingType != null ? SyntaxFactory.BaseList([SyntaxFactory.SimpleBaseType((TypeSyntax)underlyingType)]) : null,
            this.AsEnumMembers(members));
    }

Review comment (refactor):
@copilot  actually, move this up to where we do the `if (member is BaseTypeDeclarationSyntax)` and change that instead fo `if (member is BaseTypeDeclarationSyntax or DelegateDeclarationSyntax)`.  You can remove any test that shows modifiers changing now since we don't want to change them.

Code after:
                case SyntaxKind.EventDeclaration:
                    var ev = (EventDeclarationSyntax)member;
                    return this.EventDeclaration(
                        ev.Identifier.ValueText,
                        ev.Type,
                        Accessibility.NotApplicable,
                        DeclarationModifiers.None);

                case SyntaxKind.EventFieldDeclaration:
                    var ef = (EventFieldDeclarationSyntax)member;
                    return ef.WithModifiers(default);

                // convert field into property
                case SyntaxKind.FieldDeclaration:
                    var f = (FieldDeclarationSyntax)member;
                    GetAccessibilityAndModifiers(f.Modifiers, out acc, out modifiers, out _);

                    var type = GetType(f);
                    Contract.ThrowIfNull(type);

                    return AsInterfaceMember(
                        PropertyDeclaration(GetName(f), ClearTrivia(type), acc, modifiers, getAccessorStatements: null, setAccessorStatements: null));

                default:
                    throw ExceptionUtilities.UnexpectedValue(member.Kind());
            }
        });
    }

    public override SyntaxNode EnumDeclaration(
        string name,
        Accessibility accessibility,
        DeclarationModifiers modifiers,
        IEnumerable<SyntaxNode>? members)
    {
        return EnumDeclaration(name, underlyingType: null, accessibility, modifiers, members);
    }

    internal override SyntaxNode EnumDeclaration(string name, SyntaxNode? underlyingType, Accessibility accessibility = Accessibility.NotApplicable, DeclarationModifiers modifiers = default, IEnumerable<SyntaxNode>? members = null)
    {
        return SyntaxFactory.EnumDeclaration(
            default,
            AsModifierList(accessibility, modifiers, SyntaxKind.EnumDeclaration),
            name.ToIdentifierToken(),
            underlyingType != null ? SyntaxFactory.BaseList([SyntaxFactory.SimpleBaseType((TypeSyntax)underlyingType)]) : null,
            this.AsEnumMembers(members));
    }

    public override SyntaxNode EnumMember(string name, SyntaxNode? expression)
    {
        return SyntaxFactory.EnumMemberDeclaration(