Skip to content

[Foundation] Unify the FromObjectsAndKeys implementations for creating dictionaries.#24556

Merged
rolfbjarne merged 8 commits intomainfrom
dev/rolf/foundation-dictionary-creation-fixes
Jan 27, 2026
Merged

[Foundation] Unify the FromObjectsAndKeys implementations for creating dictionaries.#24556
rolfbjarne merged 8 commits intomainfrom
dev/rolf/foundation-dictionary-creation-fixes

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

  • Add two validation functions, one for when FromObjectsAndKeys is called with
    a count, and one for when FromObjectsAndKeys is called without a count.
  • Call the corresponding validation function in every FromObjectsAndKeys implementation.
  • In every FromObjectsAndKeys function without a count parameter, forward the implementation
    to the FromObjectsAndKeys with a count parameter.
  • Add numerous tests.

Consequences:

  • Specifying count=0 now succeed (creating an empty dictionary).
  • Fixed numerous cases where the count parameter was ignored.
  • Allow arrays of different lengths for the key and values array parameters when
    specifying a count.

…g dictionaries.

* Add two validation functions, one for when FromObjectsAndKeys is called with
  a count, and one for when FromObjectsAndKeys is called without a count.
* Call the corresponding validation function in every FromObjectsAndKeys implementation.
* In every FromObjectsAndKeys function without a count parameter, forward the implementation
  to the FromObjectsAndKeys with a count parameter.
* Add numerous tests.

Consequences:

* Specifying count=0 now succeed (creating an empty dictionary).
* Fixed numerous cases where the count parameter was ignored.
* Allow arrays of different lengths for the key and values array parameters when
  specifying a count.
Copy link
Copy Markdown
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 unifies the FromObjectsAndKeys implementations across NSDictionary, NSMutableDictionary, and their generic counterparts by introducing centralized validation functions and forwarding non-count implementations to count-based implementations.

Changes:

  • Added two validation helper functions in NSDictionary.cs to centralize parameter validation
  • Updated all FromObjectsAndKeys methods to use the validation functions and forward to count-based implementations
  • Added comprehensive tests for edge cases including null values, count=0, different array lengths, and invalid count values

Reviewed changes

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

Show a summary per file
File Description
src/Foundation/NSDictionary.cs Added ValidateFromObjectsAndKeys helper functions; updated FromObjectsAndKeys methods to use validation and forward to count-based overloads
src/Foundation/NSMutableDictionary.cs Updated FromObjectsAndKeys methods to use validation helpers and forward to count-based overloads
src/Foundation/NSDictionary_2.cs Updated generic FromObjectsAndKeys methods to use validation helpers and forward to count-based overloads
src/Foundation/NSMutableDictionary_2.cs Updated generic FromObjectsAndKeys methods to use validation helpers and forward to count-based overloads
tests/monotouch-test/Foundation/NSDictionaryTest.cs Added test for dictionary constructor with null values
tests/monotouch-test/Foundation/NSDictionary2Test.cs Added test for generic dictionary constructor with null values
tests/monotouch-test/Foundation/NSMutableDictionaryTest.cs Added comprehensive tests for FromObjectsAndKeys including null handling, count validation, and array length variations
tests/monotouch-test/Foundation/NSMutableDictionary2Test.cs Added comprehensive tests for generic FromObjectsAndKeys including null handling, count validation, and array length variations
tests/monotouch-test/Foundation/NSOrderedSetTest.cs Added tests for NSOrderedSet constructors with null values and arrays (appears unrelated to PR's dictionary focus)
tests/monotouch-test/Foundation/NSMutableOrderedSetTest.cs Added tests for NSMutableOrderedSet constructors with null values and arrays (appears unrelated to PR's dictionary focus)
tests/monotouch-test/Foundation/NSMutableSetTest.cs Added tests for NSMutableSet constructors with null values and arrays (appears unrelated to PR's dictionary focus)

Comment thread tests/monotouch-test/Foundation/NSMutableOrderedSetTest.cs Outdated
Comment thread src/Foundation/NSDictionary.cs Outdated
Comment thread src/Foundation/NSDictionary_2.cs Outdated
Comment thread src/Foundation/NSDictionary.cs Outdated
Comment thread src/Foundation/NSDictionary.cs Outdated
Comment thread tests/monotouch-test/Foundation/NSOrderedSetTest.cs Outdated
Comment thread tests/monotouch-test/Foundation/NSMutableSetTest.cs Outdated
@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.

@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
Copy link
Copy Markdown
Collaborator

✅ [CI Build #d1e946d] Build passed (Build packages) ✅

Pipeline on Agent
Hash: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

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

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

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #d1e946d] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

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

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

Pipeline on Agent
Hash: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

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

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

Pipeline on Agent
Hash: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

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

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

Pipeline on Agent
Hash: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

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

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

Pipeline on Agent
Hash: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

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

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

Pipeline on Agent
Hash: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne enabled auto-merge (squash) January 27, 2026 20:37
@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #d1e946d] 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. 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. [attempt 2] 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. [attempt 3] 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: d1e946d7d4dc916a37c94286aead2a5da82dd2c6 [PR build]

@rolfbjarne rolfbjarne merged commit a550d14 into main Jan 27, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants