Skip to content

[Foundation] Improve NSArray.FromNativeObjects slightly.#24509

Merged
rolfbjarne merged 3 commits intomainfrom
dev/rolf/foundation-nullability-44-nsarray-fromnativeobjects
Jan 16, 2026
Merged

[Foundation] Improve NSArray.FromNativeObjects slightly.#24509
rolfbjarne merged 3 commits intomainfrom
dev/rolf/foundation-nullability-44-nsarray-fromnativeobjects

Conversation

@rolfbjarne
Copy link
Member

  • Enable nullability.
  • Reuse existing code to create the native array.
  • Add tests.
  • Add xml docs.
  • Update nullability in some of the consumers of NSArray.FromNativeObjects
    whenever it makes sense.

Contributes towards #17285.

* Enable nullability.
* Reuse existing code to create the native array.
* Add tests.
* Add xml docs.
* Update nullability in some of the consumers of NSArray.FromNativeObjects
  whenever it makes sense.

Contributes towards #17285.
Copy link
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

This PR improves the NSArray.FromNativeObjects method by enabling nullable reference types, adding XML documentation, improving performance by reusing existing code to create native arrays, and updating nullability annotations in consumer methods. The changes also add comprehensive tests to verify null value handling in dictionary and ordered set operations.

Changes:

  • Enabled nullable reference types for NSArray.FromNativeObjects methods and added comprehensive XML documentation
  • Refactored NSArray.FromNativeObjects to use FromIntPtrs instead of manual marshaling, eliminating memory allocation/deallocation overhead
  • Updated nullability in NSDictionary, NSDictionary<TKey,TValue>, and NSMutableOrderedSet<TKey> methods to accept nullable arrays
  • Added comprehensive tests for null value handling in dictionaries and ordered sets

Reviewed changes

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

Show a summary per file
File Description
src/Foundation/NSArray.cs Enabled nullable reference types, added XML docs, refactored to use FromIntPtrs, added negative count validation
src/Foundation/NSDictionary.cs Updated method signatures to accept NSObject?[] and improved XML documentation
src/Foundation/NSDictionary_2.cs Updated generic method signatures to accept nullable arrays and refactored to call count-based overload
src/Foundation/NSMutableOrderedSet_1.cs Updated method signatures to accept nullable arrays and improved XML documentation
tests/monotouch-test/Foundation/NSDictionaryTest.cs Added tests for null value handling in non-generic dictionaries
tests/monotouch-test/Foundation/NSDictionary2Test.cs Added tests for null value handling in generic dictionaries
tests/monotouch-test/Foundation/NSMutableOrderedSet1Test.cs Added tests for null value handling in ordered set operations
Comments suppressed due to low confidence (1)

src/Foundation/NSDictionary.cs:191

  • The error message is not descriptive. It should explain what is wrong with the count parameter. Consider using a message like "count must be between 1 and the array length" for clarity.
			if (count < 1 || objects.Length < count || keys.Length < count)
				throw new ArgumentException ("count");

@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.

@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.

@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.

@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.

@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 January 15, 2026 17:38
@rolfbjarne rolfbjarne disabled auto-merge January 15, 2026 17:38
@rolfbjarne rolfbjarne enabled auto-merge (squash) January 15, 2026 17:39
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #559acab] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #559acab] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
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: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #559acab] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #559acab] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #559acab] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #559acab] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #559acab] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #559acab] Tests on macOS arm64 - Mac Tahoe (26) passed 💻

All tests on macOS arm64 - Mac Tahoe (26) passed.

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build #559acab] 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
✅ 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. [attempt 2] 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: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 9 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 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

Pipeline on Agent
Hash: 559acabb379a1b6d7dc905f4135d46363860479a [PR build]

@rolfbjarne rolfbjarne merged commit e04fa82 into main Jan 16, 2026
45 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