refactor: Consolidate duplicated generator logic into GeneratorUtils#1468
Conversation
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move shared code generation logic from 4 generator files to GeneratorUtils.cs: - GenerateCliAttributeString(): CLI attribute generation (42 lines) - GenerateValidationAttributes(): Validation attribute generation (14 lines) - GenerateXmlDocumentation(): XML doc comment generation (10+ locations) - GenerateMethodNameFromCommandParts(): Full method name from command parts - GenerateMethodNameFromLastCommandPart(): Method name from last segment This reduces ~80 lines of duplicated code across: - OptionsClassGenerator.cs - GlobalOptionsBaseGenerator.cs - ServiceInterfaceGenerator.cs - ServiceImplementationGenerator.cs - SubDomainClassGenerator.cs Fixes #1456 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryConsolidates ~80 lines of duplicated generator code into shared utility methods in GeneratorUtils.cs. Critical IssuesNone found ✅ Suggestions1. Minor case handling inconsistency in GenerateMethodNameFromCommandParts (GeneratorUtils.cs:207)The new shared method uses .ToLowerInvariant() for the rest of the string with a length check: But the original implementation in ServiceImplementationGenerator.cs used: The new version adds a length check which is safer and prevents potential index out of bounds if a part is a single character. This is actually an improvement, but means the generated code output may differ in edge cases with single-character command parts. Verify this doesn't break existing generated output. 2. Consider adding unit tests for the new utility methodsThe PR consolidates critical code generation logic. Adding unit tests for these methods would:
Example test cases:
Verdict✅ APPROVE - Well-executed refactoring with proper DRY principles. The code consolidation is sound and maintains the original behavior (with one minor safety improvement noted above). |
Summary
GeneratorUtils.csGenerateCliAttributeString(),GenerateValidationAttributes(),GenerateXmlDocumentation(),GenerateMethodNameFromCommandParts(), andGenerateMethodNameFromLastCommandPart()OptionsClassGenerator.cs,GlobalOptionsBaseGenerator.cs,ServiceInterfaceGenerator.cs,ServiceImplementationGenerator.cs, andSubDomainClassGenerator.csDetails
The following duplicated logic has been consolidated:
GenerateCliAttributeString()GenerateValidationAttributes()GenerateXmlDocumentation()GenerateMethodNameFromCommandParts()GenerateMethodNameFromLastCommandPart()Fixes #1456
Test plan
dotnet build tools/ModularPipelines.OptionsGenerator🤖 Generated with Claude Code