Skip to content

[src] Convert manual binding factories to [FactoryMethod] - #26376

Merged
rolfbjarne merged 10 commits into
mainfrom
dev/rolf/factorymethod-conversions
Aug 4, 2026
Merged

[src] Convert manual binding factories to [FactoryMethod]#26376
rolfbjarne merged 10 commits into
mainfrom
dev/rolf/factorymethod-conversions

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Convert five hand-written failable-initializer factory helpers to use the new bgen [FactoryMethod] attribute (added in #26196). Each conversion replaces an [Internal] NativeHandle _InitWith... helper plus a manual partial-class factory method with a [FactoryMethod] [return: NullAllowed] NativeHandle Constructor (...) in the binding definition, letting the generator emit the public static T? Create (...) factory. The manual partial-class files are deleted and their entries removed from frameworks.sources.

🤖 Pull request created by Copilot

rolfbjarne and others added 5 commits July 31, 2026 15:31
…FactoryMethod]

Replace the hand-written SCVideoStreamAnalyzer.Create factory (a manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrapper around the failable
`initWithParticipantUUID:streamDirection:error:` initializer) with the bgen
[FactoryMethod] attribute on the binding constructor.

The generated `public static SCVideoStreamAnalyzer? Create (string
participantUuid, SCVideoStreamAnalyzerStreamDirection streamDirection, out
NSError? error)` is identical to the previous manual factory (same name,
signature, nullable return, nil-check/dispose behavior), verified against the
generated source and compiled into Microsoft.iOS.dll. The manual partial-class
file is deleted and its frameworks.sources entry removed. This binding has
monotouch-test coverage (SCVideoStreamAnalyzerTest).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
Replace the hand-written AVCaptureEventSound.Create factory (a manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrapper around the failable
`initWithURL:error:` initializer) with the bgen [FactoryMethod] attribute on
the binding constructor.

The generated `public static AVCaptureEventSound? Create (NSUrl url, out
NSError? error)` is identical to the previous manual factory (same name,
signature, nullable return, nil-check/dispose behavior), verified against the
generated source and compiled into Microsoft.iOS.dll. The manual partial-class
file is deleted and its frameworks.sources entry removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
…[FactoryMethod]

Replace the hand-written AVSpeechSynthesisProviderAudioUnit.Create factory (a
manual `new (NSObjectFlag.Empty)` + InitializeHandle wrapper around the failable
`initWithComponentDescription:options:error:` initializer) with the bgen
[FactoryMethod] attribute on the binding constructor.

The generated `public static AVSpeechSynthesisProviderAudioUnit? Create
(AudioComponentDescription componentDescription, AudioComponentInstantiationOptions
options, out NSError? error)` is identical to the previous manual factory (same
name, signature, nullable return, nil-check/dispose behavior). The binding init
parameter was renamed outError -> error to preserve the public parameter name.
Verified against the generated source and compiled into Microsoft.iOS.dll. The
manual partial-class file is deleted and its frameworks.sources entry removed.
This binding has monotouch-test coverage (AVSpeechSynthesisProviderAudioUnitTest).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
…ethod]

Replace the two hand-written BAAssetPackManifest.Create factories (manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrappers around the failable
`initWithContentsOfURL:applicationGroupIdentifier:error:` and
`initFromData:applicationGroupIdentifier:error:` initializers) with the bgen
[FactoryMethod] attribute on two binding constructors.

The generated `public static BAAssetPackManifest? Create (NSUrl url, string
applicationGroupIdentifier, out NSError? error)` and `Create (NSData data,
string applicationGroupIdentifier, out NSError? error)` overloads are identical
to the previous manual factories (same names, signatures, nullable return,
nil-check/dispose behavior), verified against the generated source and compiled
into Microsoft.iOS.dll. The manual partial-class file is deleted and its
frameworks.sources entry removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
Replace the two hand-written WKWebExtensionMatchPattern.Create factories (manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrappers around the failable
`initWithString:error:` and `initWithScheme:host:path:error:` initializers) with
the bgen [FactoryMethod] attribute on two binding constructors.

The generated `public static WKWebExtensionMatchPattern? Create (string @string,
out NSError? error)` and `Create (string scheme, string host, string path, out
NSError? error)` overloads are identical to the previous manual factories (same
names, signatures, nullable return, nil-check/dispose behavior), and coexist
with the existing `[Static]` `Create` overloads (matchPatternWithString: /
matchPatternWithScheme:host:path:) that take no error argument. Verified against
the generated source and compiled into Microsoft.iOS.dll. The manual
partial-class file is deleted and its frameworks.sources entry removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
Copilot AI review requested due to automatic review settings July 31, 2026 13:33
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner July 31, 2026 13:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 migrates five hand-written “failable initializer” factory implementations to bgen’s new [FactoryMethod] support, so the generator emits nullable Create(...) factories automatically and the redundant manual partial-class helpers can be removed.

Changes:

  • Replaced [Internal] NativeHandle _InitWith... init helpers with [FactoryMethod] failable constructor bindings ([return: NullAllowed] NativeHandle Constructor (...)) for five types.
  • Deleted the corresponding hand-written partial-class Create(...) implementations.
  • Removed the deleted source files from src/frameworks.sources.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/WebKit/WKWebExtensionMatchPattern.cs Deletes the manual Create(...) factory helpers for failable initializers.
src/webkit.cs Adds [FactoryMethod] constructor bindings for WKWebExtensionMatchPattern failable initializers.
src/SensitiveContentAnalysis/SCVideoStreamAnalyzer.cs Deletes the manual Create(...) factory helper.
src/sensitivecontentanalysis.cs Adds a [FactoryMethod] constructor binding for the failable initializer.
src/BackgroundAssets/BAAssetPackManifest.cs Deletes the manual Create(...) factory helpers.
src/backgroundassets.cs Adds [FactoryMethod] constructor bindings for the two failable initializers.
src/AVKit/AVCaptureEventSound.cs Deletes the manual Create(...) factory helper.
src/avkit.cs Adds a [FactoryMethod] constructor binding for the failable initializer.
src/AVFoundation/AVSpeechSynthesisProviderAudioUnit.cs Deletes the manual Create(...) factory helper.
src/avfoundation.cs Adds a [FactoryMethod] constructor binding for the failable initializer.
src/frameworks.sources Removes the deleted partial-class source files from the build inputs.

Comment thread src/backgroundassets.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.

@rolfbjarne
rolfbjarne enabled auto-merge (squash) August 3, 2026 16:52
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

⚠️ AppSizeTest expected files changed ⚠️

The AppSizeTest detected changes in the expected app size files.

To update the expected files, add a comment with the following command:

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/63ce3a4c24733754780dea246fdff248
Updated files
  • TVOS-MonoVM-interpreter-preservedapis.txt
  • TVOS-MonoVM-preservedapis.txt

Pipeline on Agent
Hash: ebfc27ff41a0cb768b0be45dc043d8f0fde78ad0 [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: 24117631a253eed7039134ea761bbd9f45dddb8b [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #2411763] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 203 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ 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 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 tests passed. [attempt 2] 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: 24117631a253eed7039134ea761bbd9f45dddb8b [PR build]

@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Aug 4, 2026
@rolfbjarne
rolfbjarne merged commit 16b3170 into main Aug 4, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/factorymethod-conversions branch August 4, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants