Skip to content

[sharpie] Add --custom-delegates option to generate named delegates instead of Func<>/Action<>#24975

Merged
rolfbjarne merged 1 commit intomainfrom
dev/rolf/sharpie-delegates
Mar 24, 2026
Merged

[sharpie] Add --custom-delegates option to generate named delegates instead of Func<>/Action<>#24975
rolfbjarne merged 1 commit intomainfrom
dev/rolf/sharpie-delegates

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

When binding ObjC blocks, sharpie normally generates Func<...> and
Action<...> types for anonymous block parameters and properties. The
new --custom-delegates option generates custom named delegate
declarations instead.

For method parameters, the delegate name is derived from the method
and parameter names (e.g. SetActionHandler). For properties, it's
derived from the property name (e.g. ActionHandler).

Implementation uses a new CustomDelegateMassager that runs as a
post-processing pass on the generated C# AST, consistent with the
existing massager architecture.

…nstead of Func<>/Action<>

When binding ObjC blocks, sharpie normally generates Func<...> and
Action<...> types for anonymous block parameters and properties. The
new --custom-delegates option generates custom named delegate
declarations instead.

For method parameters, the delegate name is derived from the method
and parameter names (e.g. SetActionHandler). For properties, it's
derived from the property name (e.g. ActionHandler).

Implementation uses a new CustomDelegateMassager that runs as a
post-processing pass on the generated C# AST, consistent with the
existing massager architecture.

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

Adds a new Sharpie.Bind option to generate named delegate declarations for ObjC block parameters/properties (instead of emitting Action<>/Func<>), implemented as a post-processing massager and covered by new/updated Sharpie parsing tests.

Changes:

  • Add --custom-delegates option plumbing through CLI parsing and binder argument forwarding.
  • Implement CustomDelegateMassager to replace anonymous delegate types with generated named delegates.
  • Extend Sharpie test fixtures (blocks + nullability) and xtro-sharpie invocation to exercise the new option.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/sharpie/Sharpie.Bind/Tools.cs Adds CLI flag parsing for custom-delegates in bind + sdkdb entrypoints.
tools/sharpie/Sharpie.Bind/ObjectiveCBinder.cs Adds UseCustomDelegates property and forwards --custom-delegates when invoking out-of-process.
tools/sharpie/Sharpie.Bind/Massagers/CustomDelegateMassager.cs New massager that generates named delegates and rewrites method/property delegate types.
tools/sharpie/Sharpie.Bind/BindingMassager.cs Registers CustomDelegateMassager in the default massager list and factory switch.
tests/xtro-sharpie/Makefile Enables --custom-delegates in common Sharpie arguments for xtro runs.
tests/sharpie/Tests/Types/Blocks.h Adds a new RUN variant to test the custom delegate output.
tests/sharpie/Tests/Types/Blocks.custom_delegates.cs New expected output for the custom-delegates variant.
tests/sharpie/Tests/Nullability.h Extends header coverage for nullable returns/params and nullable blocks.
tests/sharpie/Tests/Nullability.macosx.cs Updates expected output for new nullability test constructs (macOS).
tests/sharpie/Tests/Nullability.iphoneos.cs Updates expected output for new nullability test constructs (iOS).
tests/sharpie/Sharpie.Bind.Tests/OnDiskTests.cs Teaches the test harness to recognize -custom-delegates RUN argument.

Comment thread tools/sharpie/Sharpie.Bind/Massagers/CustomDelegateMassager.cs
Comment thread tools/sharpie/Sharpie.Bind/Massagers/CustomDelegateMassager.cs
@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #9acc540] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 9acc5407a66df164f91b681f774ad5853baa71c1 [PR build]

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

✅ [PR Build #9acc540] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 9acc5407a66df164f91b681f774ad5853baa71c1 [PR build]

@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: 9acc5407a66df164f91b681f774ad5853baa71c1 [PR build]

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

✅ [CI Build #9acc540] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 9acc5407a66df164f91b681f774ad5853baa71c1 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

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

🚀 [CI Build #9acc540] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ 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. 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. [attempt 2] 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
✅ windows: All 3 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: 9acc5407a66df164f91b681f774ad5853baa71c1 [PR build]

@rolfbjarne rolfbjarne merged commit d3ac300 into main Mar 24, 2026
52 checks passed
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