Skip to content

[tools] Extract helpers to deduplicate StaticRegistrar code#25253

Open
rolfbjarne wants to merge 2 commits intomainfrom
dev/rolf/static-registrar-dedup-helpers
Open

[tools] Extract helpers to deduplicate StaticRegistrar code#25253
rolfbjarne wants to merge 2 commits intomainfrom
dev/rolf/static-registrar-dedup-helpers

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

PrepareInterfaceMethodMapping() in StaticRegistrar.cs had two identical 8-line dictionary initialization blocks, and GetProtocolMemberAttributes() had three identical CustomAttributeArgument[] 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 for ParameterType, ParameterByRef, and ParameterBlockProxy.

Net result: +28 / −37 lines, no behavioral change.

🤖 Pull request created by Copilot

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AddMethodMapping to centralize repeated dictionary initialization + add logic in PrepareInterfaceMethodMapping.
  • Extracted ExtractAttributeArray<T> to centralize extraction of CustomAttributeArgument[] into typed arrays for ProtocolMemberAttribute properties.

Comment thread tools/common/StaticRegistrar.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

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>
@rolfbjarne rolfbjarne changed the title Extract helpers to deduplicate StaticRegistrar code [tools] Extract helpers to deduplicate StaticRegistrar code Apr 28, 2026
@rolfbjarne rolfbjarne enabled auto-merge (squash) April 28, 2026 07:28
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #454ba16] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 454ba162c5370b3f882967fa7b414a93eca19a30 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #454ba16] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 454ba162c5370b3f882967fa7b414a93eca19a30 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 454ba162c5370b3f882967fa7b414a93eca19a30 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #454ba16] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 454ba162c5370b3f882967fa7b414a93eca19a30 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🔥 [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
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 454ba162c5370b3f882967fa7b414a93eca19a30 [PR build]

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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 AddMethodMapping to centralize repeated dictionary initialization + add logic in PrepareInterfaceMethodMapping.
  • Extracted ExtractAttributeArray<T> to centralize repeated CustomAttributeArgument[] extraction and conversion in GetProtocolMemberAttributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants