[Foundation] Unify the FromObjectsAndKeys implementations for creating dictionaries.#24556
Conversation
…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.
There was a problem hiding this comment.
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) |
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.
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.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #d1e946d] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #d1e946d] 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 #d1e946d] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #d1e946d] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #d1e946d] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #d1e946d] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #d1e946d] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #d1e946d] 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.
🚀 [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 Pipeline on Agent |
a count, and one for when FromObjectsAndKeys is called without a count.
to the FromObjectsAndKeys with a count parameter.
Consequences:
specifying a count.