[sharpie] Add --custom-delegates option to generate named delegates instead of Func<>/Action<>#24975
Conversation
…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>
There was a problem hiding this comment.
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-delegatesoption plumbing through CLI parsing and binder argument forwarding. - Implement
CustomDelegateMassagerto 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. |
✅ [CI Build #9acc540] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #9acc540] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ 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 |
✅ [CI Build #9acc540] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [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 macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
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.