[http-client-csharp] Fix partial method customization rebinding#11246
Open
ArcturusZhang wants to merge 3 commits into
Open
[http-client-csharp] Fix partial method customization rebinding#11246ArcturusZhang wants to merge 3 commits into
ArcturusZhang wants to merge 3 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a8ef33da-e40d-4f79-86d7-7d947641e6b4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a8ef33da-e40d-4f79-86d7-7d947641e6b4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a8ef33da-e40d-4f79-86d7-7d947641e6b4
commit: |
Contributor
|
No changes needing a change description found. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes C# generator partial method signature customization so that customized parameter names correctly rebind into already-generated method bodies, while also addressing C# modifier ordering and async preservation for partial implementations (per #11245).
Changes:
- Rebinds generated method-body parameter references when late customization renames parameters (by renaming
ParameterProviders in-place rather than cloning). - Fixes method modifier emission order so
virtual partialis emitted in a valid order, with a dedicated unit test. - Preserves generated
asyncon partial implementations while keeping implementation parameters required (no defaults), even when custom partial declarations include optional metadata.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Writers/CodeWriterTests.cs | Adds a regression test asserting public virtual partial ... modifier ordering. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/TestData/OutputLibraryVisitorTests/PartialMethodCustomizationRenamesGeneratedBodyReferences/TestName.cs | Adds custom partial declaration test input that renames a parameter and includes virtual partial. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/OutputLibraryVisitorTests.cs | Adds regression test ensuring body references use customized parameter names and defaults are removed from implementations. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Writers/CodeWriter.cs | Adjusts modifier emission to place partial after method-specific modifiers like virtual. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/TypeProvider.cs | Switches to in-place parameter renaming for partial method customization and preserves generated async. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/PartialMethodCustomization.cs | Introduces RenameParametersInPlace helper to avoid breaking cached body references. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs | Threads generated return type/modifiers into partial signature building for protocol/convenience SCM methods. |
Comment on lines
+171
to
+187
| public static IReadOnlyList<ParameterProvider> RenameParametersInPlace( | ||
| IReadOnlyList<ParameterProvider> generatorParameters, | ||
| IReadOnlyList<ParameterProvider> customParameters, | ||
| bool removeDefaults) | ||
| { | ||
| for (int i = 0; i < generatorParameters.Count && i < customParameters.Count; i++) | ||
| { | ||
| var generatedParameter = generatorParameters[i]; | ||
| generatedParameter.Update(name: customParameters[i].Name); | ||
| if (removeDefaults) | ||
| { | ||
| generatedParameter.DefaultValue = null; | ||
| } | ||
| } | ||
|
|
||
| return generatorParameters; | ||
| } |
Contributor
|
kicked off regen preview https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6560062&view=results |
jorgerangel-msft
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11245
This fixes partial method signature customization in the C# generator:
virtual partialmethods;asyncon partial implementations;Validation:
dotnet test packages\http-client-csharp\generator\Microsoft.TypeSpec.Generator\test\Microsoft.TypeSpec.Generator.Tests.csproj --filter "FullyQualifiedName~OutputLibraryVisitorTests.PartialMethodCustomizationRenamesGeneratedBodyReferences|FullyQualifiedName~CodeWriterTests.CodeWriter_WriteMethodDeclaration_WithVirtualPartialModifier" --no-restoredotnet test packages\http-client-csharp\generator\Microsoft.TypeSpec.Generator.ClientModel\test\Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj --filter "FullyQualifiedName~ClientProviderCustomizationTests" --no-restore