Skip to content

Comments

refactor: eliminate duplicated code in source generators#307

Merged
vbreuss merged 1 commit intomainfrom
topic/refactor-source-generation
Dec 12, 2025
Merged

refactor: eliminate duplicated code in source generators#307
vbreuss merged 1 commit intomainfrom
topic/refactor-source-generation

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Dec 12, 2025

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 EscapeForXmlDoc visibility from internal to private as it's no longer needed outside its containing class

@vbreuss vbreuss self-assigned this Dec 12, 2025
Copilot AI review requested due to automatic review settings December 12, 2025 14:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EscapeForXmlDoc visibility from internal to private as 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

@vbreuss vbreuss enabled auto-merge (squash) December 12, 2025 14:41
@sonarqubecloud
Copy link

@github-actions
Copy link

Test Results

    14 files  ±0      14 suites  ±0   4m 34s ⏱️ -28s
 1 656 tests ±0   1 655 ✅ ±0  1 💤 ±0  0 ❌ ±0 
11 081 runs  ±0  11 080 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 13421cc. ± Comparison against base commit eda9bc1.

@vbreuss vbreuss merged commit 4e06377 into main Dec 12, 2025
12 checks passed
@vbreuss vbreuss deleted the topic/refactor-source-generation branch December 12, 2025 14:43
@github-actions
Copy link

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
[Host] : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.490 μs 0.0213 μs 0.0199 μs 0.2232 - 3.66 KB
Simple_Moq 178.624 μs 1.8053 μs 1.6004 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.864 μs 0.0646 μs 0.0604 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.957 μs 0.0763 μs 0.0714 μs 0.5035 - 8.33 KB

@github-actions
Copy link

This is addressed in release v0.44.0.

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

Labels

state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant