[Foundation] Improve NSArray.FromStrings a bit.#24583
Conversation
* Enable nullability. * Reuse existing code to create the native array. * Add tests. * Add xml docs. * Update nullability in some of the consumers of these methods whenever it makes sense. * Adjust CFArray.Create|FromStrings methods to match NSArray's equivalent methods. Contributes towards #17285.
There was a problem hiding this comment.
Pull request overview
This PR improves the NSArray.FromStrings methods and related CFArray methods by enabling nullability, adding better XML documentation, improving the implementation to reuse existing code, and adding comprehensive tests.
Changes:
- Enabled nullability in NSArray.FromStrings and added a new FromNullableStrings method for nullable array inputs
- Refactored NSArray.FromStrings to reuse CFArray.Create, eliminating duplicated marshaling logic
- Updated CFArray.Create and FromStrings to accept nullable strings with proper documentation
- Updated consumers (NSSet, NSOrderedSet, NSMutableSet) to accept nullable string arrays
- Added comprehensive tests for both NSArray and CFArray with null items
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Foundation/NSArray.cs | Refactored FromStrings to delegate to CFArray.Create, added FromNullableStrings method, improved XML docs, enabled nullability |
| src/CoreFoundation/CFArray.cs | Enhanced Create method with IReadOnlyList overload, updated FromStrings signature, added XML documentation |
| tests/monotouch-test/Foundation/ArrayTest.cs | Added tests for FromStrings with null items, IReadOnlyList, and FromNullableStrings |
| tests/monotouch-test/CoreFoundation/ArrayTest.cs | Added tests for Create and FromStrings with null items and IReadOnlyList |
| src/bgen/Generator.cs | Updated generator to use FromNullableStrings for nullable string arrays |
| src/Foundation/NSSet.cs | Updated constructor to accept nullable string arrays |
| src/Foundation/NSOrderedSet.cs | Updated constructors to accept nullable string arrays |
| src/Foundation/NSMutableSet.cs | Updated constructor to accept nullable string arrays |
| src/CoreText/CTFont.cs | Updated GetDefaultCascadeList to use FromNullableStrings |
| src/CoreServices/FSEvents.cs | Fixed logic to properly check for null before checking Count |
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.
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.
…ullability-44-nsarray-fromstrings
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.
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.
…ullability-44-nsarray-fromstrings
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.
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.
…ullability-44-nsarray-fromstrings
✅ [PR Build #e219ead] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ [CI Build #e219ead] Build passed (Build packages) ✅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 #e219ead] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #e219ead] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #e219ead] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #e219ead] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #e219ead] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #e219ead] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
🚀 [CI Build #e219ead] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 117 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Contributes towards #17285.