-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Refactor RequestDelegateGenerator to use partial class pattern #64755
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
Refactor RequestDelegateGenerator to use partial class pattern #64755
Conversation
…alidationsGenerator and OpenApiGenerator Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
There was a problem hiding this 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 restructures the RequestDelegateGenerator to follow the partial class pattern used by other generators in the repository (ValidationsGenerator and OpenApiGenerator). The generator is split into three focused files: the main file containing the pipeline setup (Initialize), a parser file with syntax predicate and transformation logic, and an emitter file with all code generation methods.
Key changes:
- Separated parsing and emission logic into dedicated partial class files
- Converted inline lambdas to named methods for better organization
- Maintained all existing functionality without behavioral changes
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
RequestDelegateGenerator.cs |
Simplified to contain only pipeline setup; extracted parsing and emission logic |
RequestDelegateGenerator.Parser.cs |
New file with predicate and transform methods for endpoint detection |
RequestDelegateGenerator.Emitter.cs |
New file with all code generation methods previously inline in Initialize |
Comments suppressed due to low confidence (1)
src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator/RequestDelegateGenerator.cs:1
- The logical condition differs from the original code. The original used
||(OR), but this uses&&(AND). This changes the behavior: the original wrotepattern,when the method was NOT MapFallback OR when there were NOT exactly 2 arguments. The new code writespattern,only when BOTH conditions are true. This should be||to match the original logic.
// Licensed to the .NET Foundation under one or more agreements.
| } | ||
| var code = RequestDelegateGeneratorSources.GetGeneratedRouteBuilderExtensionsSource( | ||
| endpoints: stringWriter.ToString(), | ||
| helperMethods: helperMethods ?? string.Empty, |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null-coalescing operator is redundant here since the calling code already ensures helperMethods is never null (see line 59 where it's passed as helperMethods ?? string.Empty). Consider removing this defensive check or the one at the call site.
| helperMethods: helperMethods ?? string.Empty, | |
| helperMethods: helperMethods, |
Refactor RequestDelegateGenerator to use partial class pattern
Restructure RequestDelegateGenerator to match ValidationsGenerator and OpenApiGenerator patterns
Description
Refactors
RequestDelegateGeneratorto use the same partial class structure asValidationsGenerator(src/Validation/gen) andXmlCommentGenerator(src/OpenApi/gen).Changes
RequestDelegateGenerator.cs— Now contains only theInitializemethod (pipeline setup)RequestDelegateGenerator.Parser.cs(new) — Parsing logic:IsEndpointInvocation— Predicate for identifying Map* invocationsTransformEndpoint— Creates endpoint models from syntax contextsRequestDelegateGenerator.Emitter.cs(new) — Emission logic:EmitInterceptorDefinition— Generates interceptor method codeEmitHttpVerbs,EmitEndpointHelpers,EmitHelperTypes— Collect and emit supporting codeEmit— Final source outputStructure
No functional changes — existing tests pass unchanged.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.