[Foundation] Improve NSArray.From[NS]Objects slightly.#24569
[Foundation] Improve NSArray.From[NS]Objects slightly.#24569rolfbjarne merged 4 commits intomainfrom
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. * Add a 'nint count' overload to a few methods that takes 'int count', so that we use 'nint' for 'count' everywhere, and deprecated the 'int count' overloads. Contributes towards #17285.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR improves the NSArray.FromNSObjects and FromObjects methods by enabling nullability, adding comprehensive XML documentation, refactoring to reuse existing code, adding nint count overloads, and wrapping the old int count overloads in conditional compilation for removal in XAMCORE 5.0.
Changes:
- Enabled nullability for NSArray factory methods and updated parameter/return types to properly indicate nullable elements
- Added comprehensive XML documentation for all public NSArray factory methods
- Refactored internal implementation to reuse
FromIntPtrsand consolidated logic intoFromNativeObjectsImpl - Added
nint countoverloads for consistency across the API surface - Wrapped deprecated
int countoverloads in#if !XAMCORE_5_0for future removal - Updated consumers (NSOrderedSet, NSMutableSet, NSDictionary, etc.) to use nullable types
- Added comprehensive test coverage for new and existing functionality
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Foundation/NSArray.cs | Main implementation changes: enabled nullability, added XML docs, refactored to reuse code, added nint count overloads, deprecated int count overloads |
| src/Foundation/NSOrderedSet.cs | Updated constructor and MakeNSOrderedSet to use nullable parameters |
| src/Foundation/NSMutableSet.cs | Updated constructors to use nullable parameters |
| src/Foundation/NSMutableSet_1.cs | Refactored to use FromNonNullNativeObjects instead of manual null checks |
| src/Foundation/NSDictionary.cs | Updated constructors and helper methods to use nullable parameters |
| src/Foundation/NSDictionary_2.cs | Updated constructors and methods to use nullable parameters, changed From to FromNativeObjects |
| src/Foundation/NSMutableDictionary.cs | Updated FromObjectsAndKeys methods to use nullable parameters |
| src/Foundation/NSMutableDictionary_2.cs | Updated constructors and methods to use nullable parameters |
| src/AudioUnit/AudioComponent.cs | Updated lambda to handle nullable Dictionary property |
| tests/monotouch-test/Foundation/NSArray1Test.cs | Added comprehensive tests for new functionality and edge cases |
| tests/monotouch-test/Foundation/NSOrderedSetTest.cs | Added tests for nullable constructors and methods |
| tests/monotouch-test/Foundation/NSMutableSetTest.cs | Added tests for nullable constructors |
| tests/monotouch-test/Foundation/NSMutableOrderedSetTest.cs | Added tests for nullable constructors |
| tests/cecil-tests/HandleSafety.KnownFailures.cs | Updated method signature reference from FromNativeObjects to FromNativeObjectsImpl |
| tests/cecil-tests/Documentation.KnownFailures.txt | Removed entries for methods that now have documentation |
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.
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-fromnsobjects
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #0393474] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #0393474] 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 #0393474] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #0393474] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #0393474] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #0393474] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #0393474] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #0393474] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
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.
🚀 [CI Build #0393474] 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.