-
Notifications
You must be signed in to change notification settings - Fork 549
[Foundation] Fix nullability in NSMutableDictionary<TKey, TValue>. #24458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Foundation] Fix nullability in NSMutableDictionary<TKey, TValue>. #24458
Conversation
This is file 40 of 47 files with nullability disabled in Foundation.
* Enabled nullable reference types.
* Removed four SupportedOSPlatform attributes without version numbers.
* Replaced 'To be added.' XML comments with proper documentation.
* Added XML documentation for all public and protected members.
* Used ArgumentNullException.ThrowIfNull for parameter validation.
* Fixed XML comment formatting and added see cref attributes.
* Made ObjectForKey return nullable TValue? since keys may not exist.
* Made TryGetValue parameter nullable with NotNullWhen(true) attribute.
* Kept IDictionary interface implementations non-nullable per .NET contract.
* Used KeyNotFoundException when indexer accesses missing keys.
* Fixed IEnumerator implementations to skip null values in enumeration.
* Changed empty array initialization from 'new TValue[]{}' to '[]'.
* Remove some dead code.
* Add a few more tests.
Contributes towards #17285.
There was a problem hiding this 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 enables nullable reference types for NSMutableDictionary<TKey, TValue>, which is file 40 of 47 in the Foundation nullability migration effort. The changes improve type safety by making nullability explicit in method signatures, particularly for methods that can return null for missing keys like ObjectForKey. The PR also improves the indexer behavior to throw KeyNotFoundException for missing keys (aligning with .NET conventions), replaces placeholder XML documentation with comprehensive summaries, and modernizes parameter validation using ArgumentNullException.ThrowIfNull.
Key changes:
- Made
ObjectForKeyreturnTValue?(nullable) since keys may not exist in the dictionary - Changed public indexer getter to throw
KeyNotFoundExceptionfor missing keys instead of returning null - Added comprehensive XML documentation for all public members
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Foundation/NSMutableDictionary_2.cs | Enabled nullable reference types, updated method signatures for nullability, replaced placeholder XML docs with comprehensive documentation, modernized parameter validation, changed indexer to throw KeyNotFoundException for missing keys |
| tests/monotouch-test/Foundation/NSMutableDictionary2Test.cs | Added comprehensive tests for missing key access behavior, testing ObjectForKey, TryGetValue, ContainsKey, indexer, and IDictionary interface behavior |
| tests/cecil-tests/Documentation.KnownFailures.txt | Removed entries for methods that now have proper XML 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.
✅ [CI Build #e865530] Build passed (Build packages) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #e865530] Build passed (Detect API changes) ✅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 #e865530] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
💻 [CI Build #e865530] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
💻 [CI Build #e865530] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #e865530] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #e865530] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #e865530] 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.
✅ 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 |
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 #e865530] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 2 tests failed, 120 tests passed. Failures❌ monotouch tests (macOS) [attempt 3]2 tests failed, 10 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
This is file 40 of 47 files with nullability disabled in Foundation.
Contributes towards #17285.