refactor: eliminate duplicated code in source generators#307
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors source generator code to eliminate duplication by extracting common XML documentation generation patterns into reusable helper methods. The changes consolidate repetitive string-building logic for generic type parameters and XML documentation tags.
Key changes:
- Introduced helper methods (
GetGenericTypeParameters,GetOutGenericTypeParameters,AppendXmlSummary,AppendXmlRemarks,GetTypeParametersDescription,AppendTypeParamDocs,GetAdditionalInterfacesDescription) to replace duplicated code patterns - Replaced inline XML documentation generation with calls to these helper methods across multiple source generator files
- Changed
EscapeForXmlDocvisibility frominternaltoprivateas it's no longer needed outside its containing class
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Sources.cs | Added new helper methods for generating XML documentation and generic type parameters; refactored existing code to use these helpers |
| Sources.MethodSetups.cs | Replaced duplicated XML documentation code with helper method calls for method setup interfaces and classes |
| Sources.IndexerSetups.cs | Replaced duplicated XML documentation code with helper method calls for indexer setup interfaces and classes |
|
🚀 Benchmark ResultsDetails
|
|
This is addressed in release v0.44.0. |



This PR refactors source generator code to eliminate duplication by extracting common XML documentation generation patterns into reusable helper methods. The changes consolidate repetitive string-building logic for generic type parameters and XML documentation tags.
Key changes:
GetGenericTypeParameters,GetOutGenericTypeParameters,AppendXmlSummary,AppendXmlRemarks,GetTypeParametersDescription,AppendTypeParamDocs,GetAdditionalInterfacesDescription) to replace duplicated code patternsEscapeForXmlDocvisibility frominternaltoprivateas it's no longer needed outside its containing class