Skip to content

Conversation

@rolfbjarne
Copy link
Member

This is file 41 of 47 files with nullability disabled in Foundation.

  • Removes SupportedOSPlatform attributes without version numbers.
  • Enables nullability and adds nullability attributes where appropriate.
  • Replaces 'To be added' XML comments with proper documentation.
  • Adds missing XML documentation for all public members.
  • Uses ArgumentNullException.ThrowIfNull consistently.
  • Uses modern C# array syntax ([]) for empty arrays.
  • Improves IDictionary interface implementation to properly handle missing keys.
  • Adds some tests.

Contributes towards #17285.

This is file 41 of 47 files with nullability disabled in Foundation.

* Removes SupportedOSPlatform attributes without version numbers.
* Enables nullability and adds nullability attributes where appropriate.
* Replaces 'To be added' XML comments with proper documentation.
* Adds missing XML documentation for all public members.
* Uses ArgumentNullException.ThrowIfNull consistently.
* Uses modern C# array syntax ([]) for empty arrays.
* Improves IDictionary interface implementation to properly handle missing keys.
* Adds some tests.

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 enables nullable reference types for NSDictionary<TKey, TValue> in the Foundation namespace, part of an ongoing effort to enable nullability across 47 files (this is file 41). The changes improve code safety through nullability annotations, modernize the code with C# best practices, and enhance documentation quality by replacing placeholder XML comments with detailed descriptions.

Key changes:

  • Enables #nullable and adds appropriate nullability annotations throughout the class
  • Replaces ArgumentNullException null checks with ArgumentNullException.ThrowIfNull for consistency
  • Uses modern C# empty array syntax [] instead of new TValue[] {}
  • Adds comprehensive XML documentation for all public members
  • Adds tests for missing key access scenarios to verify IDictionary interface behavior

Reviewed changes

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

File Description
src/Foundation/NSDictionary_2.cs Enables nullability, adds proper XML documentation, uses modern C# syntax, and improves IDictionary implementation with correct nullability annotations
tests/monotouch-test/Foundation/NSDictionary2Test.cs Adds comprehensive tests for missing key scenarios, validating that both class and IDictionary interface return null instead of throwing exceptions
tests/cecil-tests/Documentation.KnownFailures.txt Removes entries for methods and properties that now have proper documentation
src/NaturalLanguage/NLLanguage.cs Refactors enumeration pattern to use KeyValuePair iteration for improved efficiency

Comment on lines +365 to +379
public void IndexerGetterThrowsKeyNotFoundTest ()
{
var value1 = NSDate.FromTimeIntervalSinceNow (1);
var key1 = new NSString ("key1");
var keyMissing = new NSString ("missing");

var dict = new NSDictionary<NSString, NSDate> (key1, value1);

// Accessing via the property indexer should return null for missing keys
Assert.IsNull (dict [keyMissing], "missing key");

// Accessing via IDictionary interface should also return null (NSDictionary behavior)
IDictionary<NSString, NSDate> idict = dict;
Assert.IsNull (idict [keyMissing], "missing key via interface");
}
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name IndexerGetterThrowsKeyNotFoundTest is misleading. The test actually verifies that the indexer returns null for missing keys, not that it throws KeyNotFoundException. Consider renaming to IndexerGetterReturnsNullForMissingKeyTest to accurately reflect the behavior being tested.

Copilot uses AI. Check for mistakes.
// Indexer getter should return null for missing keys
Assert.IsNull (dict [keyMissing], "Indexer missing");

// IDictionary indexer should also return null (NSDictionary can have null values)
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "NSDictionary can have null values" but this contradicts the implementation comment on line 378 of NSDictionary_2.cs which states "NSDictionary can not contain NULLs, if you want a NULL, it exists as an NSNull". The comment should be corrected to clarify that NSDictionary returns null for missing keys, not that it stores null values.

Suggested change
// IDictionary indexer should also return null (NSDictionary can have null values)
// IDictionary indexer should also return null for missing keys (NSDictionary returns null for missing keys, not because it stores null values)

Copilot uses AI. Check for mistakes.
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #8eda040] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 8eda040026413504e282a428a1c17b563d459279 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 8eda040026413504e282a428a1c17b563d459279 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #8eda040] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 8eda040026413504e282a428a1c17b563d459279 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 8eda040026413504e282a428a1c17b563d459279 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 8eda040026413504e282a428a1c17b563d459279 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

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

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 8eda040026413504e282a428a1c17b563d459279 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 8eda040026413504e282a428a1c17b563d459279 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #8eda040] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

1 tests crashed, 2 tests failed, 106 tests passed.

Failures

❌ cecil tests

1 tests failed, 0 tests passed.

Failed tests

  • Cecil-based tests: Failed (Execution failed with exit code 1)
    • Cecil.Tests.Documentation.VerifyEveryVisibleMemberIsDocumented: Found 2 undocumented APIs (not known failures) and 0 APIs that were marked as known failures but are now documented. If this is ...

Html Report (VSDrops) Download

❌ introspection tests

1 tests failed, 3 tests passed.

Failed tests

  • introspection/tvOS - simulator/Debug: Crashed

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

🔥 Failed catastrophically on VSTS: test results - monotouch_ios (no summary found).

Html Report (VSDrops) Download

Successes

✅ 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
✅ linker: All 44 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: 8eda040026413504e282a428a1c17b563d459279 [PR build]

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.

3 participants