[tools] Extract helpers to deduplicate StaticRegistrar code#25253
[tools] Extract helpers to deduplicate StaticRegistrar code#25253rolfbjarne wants to merge 2 commits intomainfrom
Conversation
Extract AddMethodMapping() to deduplicate the dictionary initialization blocks in PrepareInterfaceMethodMapping(). Extract ExtractAttributeArray<T>() to deduplicate the three identical CustomAttributeArgument[] extraction blocks in GetProtocolMemberAttributes(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Refactors StaticRegistrar.cs to remove small blocks of duplicated logic in the static registrar’s interface method mapping and protocol member attribute parsing.
Changes:
- Extracted
AddMethodMappingto centralize repeated dictionary initialization + add logic inPrepareInterfaceMethodMapping. - Extracted
ExtractAttributeArray<T>to centralize extraction ofCustomAttributeArgument[]into typed arrays forProtocolMemberAttributeproperties.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Keep the explicit cast to CustomAttributeArgument[] so that unexpected types throw an InvalidCastException, matching the original inlined behavior. The 'is not' pattern would silently return null instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #454ba16] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #454ba16] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #454ba16] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #454ba16] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 0 tests failed, 153 tests passed. Failures❌ windows tests🔥 Failed catastrophically on VSTS: test results - windows (no summary found). Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
There was a problem hiding this comment.
Pull request overview
This PR refactors StaticRegistrar to reduce duplicated code in interface-method mapping and protocol member attribute extraction, without changing behavior. It improves maintainability of the registrar logic used by the tooling layer.
Changes:
- Extracted
AddMethodMappingto centralize repeated dictionary initialization + add logic inPrepareInterfaceMethodMapping. - Extracted
ExtractAttributeArray<T>to centralize repeatedCustomAttributeArgument[]extraction and conversion inGetProtocolMemberAttributes.
PrepareInterfaceMethodMapping()inStaticRegistrar.cshad two identical 8-line dictionary initialization blocks, andGetProtocolMemberAttributes()had three identicalCustomAttributeArgument[]extraction blocks in its switch statement.This PR extracts two small helpers to eliminate the duplication:
AddMethodMapping()— consolidates the repeated dictionary-init-and-add pattern used for both explicit and implicit interface method mapping.ExtractAttributeArray<T>()— consolidates the repeated null-check + cast + copy loop forParameterType,ParameterByRef, andParameterBlockProxy.Net result: +28 / −37 lines, no behavioral change.
🤖 Pull request created by Copilot