Repository navigation
Support extension members in API diff - #55356
Conversation
Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
- Multiple extension blocks for different, same, and alternating target types - Generic static extension members - Constrained and unconstrained generic instance and static members at block and member levels Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR updates the API diff pipeline to preserve C# extension(...) { ... } blocks in generated API baselines/diffs, while suppressing the compiler-generated “implementation” methods that would otherwise show up as ordinary members on the containing type. It also adds dedicated test coverage to validate the resulting diff output for extension members (methods/properties, generic/constrained cases, multiple blocks/receiver types).
Changes:
- Add MSTest coverage for extension-member additions/changes/deletions and multi-block scenarios.
- Update GenAPI C# document generation to filter out extension-block implementation methods when emitting members.
- Update the in-memory diff generator to normalize extension-block receiver formatting and treat extension blocks as public/protected-visible members for diff purposes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/Microsoft.DotNet.ApiDiff.Tests/Diff.ExtensionMember.Tests.cs | Adds API diff tests covering extension blocks and extension members across multiple shapes (static/instance, generic, constrained, multi-block). |
| src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/CSharpAssemblyDocumentGenerator.cs | Filters named-type members to suppress compiler-generated implementation methods for extension members while preserving extension blocks. |
| src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/MemoryOutputDiffGenerator.cs | Normalizes unnamed receiver formatting in extension blocks and ensures extension blocks participate in member visibility selection for diffs. |
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/CSharpAssemblyDocumentGenerator.cs:326
- IsMatchingExtensionMethod can return true for unrelated overloads because it never validates the receiver parameter type. For example, an ordinary method
M(string)could be incorrectly treated as the compiler-generated implementation for an instance extension memberM()onextension(int ...), since the current check only compares name/arity/return type and then zips non-receiver parameters (which are empty). Adding a receiver-type check (derived from the extension block’s receiver constructor parameter) makes the filter safe.
int receiverParameterCount = extensionMethod.IsStatic ? 0 : 1;
if (implementation.Name != extensionMethod.Name ||
implementation.Arity != extensionBlock.Arity + extensionMethod.Arity ||
implementation.Parameters.Length != extensionMethod.Parameters.Length + receiverParameterCount ||
!HasMatchingType(implementation.ReturnType, extensionMethod.ReturnType))
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Preserves C# extension blocks in API diffs, suppresses compiler-generated implementation methods, and adds extension-member test coverage.
Original context: API diff between .NET 11 Preview 5 and .NET 11 Preview 6 (dotnet/core#10485)