[http-client-csharp] Fix partial method customization rebinding - #11246
[http-client-csharp] Fix partial method customization rebinding#11246Dapeng Zhang (ArcturusZhang) wants to merge 4 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: |
|
No changes needing a change description found. |
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. |
| 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; | ||
| } |
|
kicked off regen preview https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6560062&view=results |
|
Hi @Dapeng Zhang (@ArcturusZhang). Your PR has had no update for 14 days and it is marked as a stale PR. If it is not updated within 14 additional days, the PR will automatically be closed. If you want to refresh the PR, please remove the |
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