Skip to content

Improve C# Code Generator to use Roslyn SyntaxFactory instead of basic string concatenation #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2025

Conversation

rudyhuyn
Copy link
Collaborator

@rudyhuyn rudyhuyn commented Mar 9, 2025

This PR refactors the C# code generator to use Roslyn’s SyntaxFactory API instead of manually concatenating strings to build C# source files.

@rudyhuyn rudyhuyn changed the title Improve C# Code Generator to Use Roslyn SyntaxFactory Instead of String Concatenation Improve C# Code Generator to use Roslyn SyntaxFactory instead of basic string concatenation Mar 9, 2025
@rudyhuyn rudyhuyn merged commit e6dafb6 into main Mar 9, 2025
3 checks passed
@rudyhuyn rudyhuyn deleted the user/rudy/useSyntaxFactory branch March 9, 2025 10:10
@Sergio0694
Copy link
Contributor

This PR just made the generator much, much slower and less efficient. It is highly discouraged to use syntax factory APIs to create source generator text, as they're orders of magnitude slower than just building a string. See: dotnet/roslyn#52914 (comment).

You should copy the IndentedTextWriter type (eg. here) and use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants