Skip to content

Commit 6ee9375

Browse files
rolfbjarneCopilot
andauthored
[Foundation] Fix nullability in NSObject. (#24481)
This is file 43 of 47 files with nullability disabled in Foundation. * Enables nullability. * Removes SupportedOSPlatform attributes without version numbers from NSObject and NSObservedChange classes. * Replaces XML include attributes with inlined content from NSObjectFlag.xml and NSObservedChange.xml. * Removes 'To be added' XML comments with proper documentation. * Adds missing XML documentation for public and protected members. * Improves XML comments for language, grammar, consistency and correctness. * Adds see cref attributes for type and member references. * Removes unnecessary whitespace in XML comments. Contributes towards #17285. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 526a773 commit 6ee9375

File tree

15 files changed

+298
-271
lines changed

15 files changed

+298
-271
lines changed

docs/api/Foundation/NSObjectFlag.xml

Lines changed: 0 additions & 61 deletions
This file was deleted.

docs/api/Foundation/NSObservedChange.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/AppKit/NSColor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public void GetComponents (out nfloat [] components)
442442
/// <summary>To be added.</summary>
443443
/// <returns>To be added.</returns>
444444
/// <remarks>To be added.</remarks>
445-
public override string ToString ()
445+
public override string? ToString ()
446446
{
447447
try {
448448
string name = this.ColorSpaceName;

src/CoreBluetooth/CBUUID.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public unsafe bool Equals (CBUUID? obj)
110110
/// <summary>To be added.</summary>
111111
/// <returns>To be added.</returns>
112112
/// <remarks>To be added.</remarks>
113-
public override bool Equals (object obj)
113+
public override bool Equals (object? obj)
114114
{
115115
return base.Equals (obj);
116116
}

src/CoreFoundation/CFException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static CFException FromCFError (IntPtr cfErrorHandle, bool release)
144144
using (var userInfo = new NSDictionary (cfUserInfo)) {
145145
foreach (var i in userInfo) {
146146
if (i.Key is not null)
147-
e.Data.Add (i.Key.ToString (), i.Value?.ToString ());
147+
e.Data.Add (i.Key.ToString () ?? "", i.Value?.ToString () ?? "");
148148
}
149149
}
150150
}

src/CoreImage/CIDetectorOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ internal NSDictionary ToDictionary ()
8989
// Tracking exists only in iOS6+, before this the field is null (and would throw if used)
9090
if (CIDetector.Tracking is not null && TrackingEnabled is not null) {
9191
keys.Add (CIDetector.Tracking);
92-
values.Add (NSObject.FromObject (TrackingEnabled.Value));
92+
values.Add (NSObject.FromObject (TrackingEnabled.Value)!);
9393
}
9494

9595
// EyeBlink exists only in iOS7+, before this the field is null (and would throw if used)
9696
if (CIDetector.EyeBlink is not null && EyeBlink is not null) {
9797
keys.Add (CIDetector.EyeBlink);
98-
values.Add (NSObject.FromObject (EyeBlink.Value));
98+
values.Add (NSObject.FromObject (EyeBlink.Value)!);
9999
}
100100

101101
// Smile exists only in iOS7+, before this the field is null (and would throw if used)
102102
if (CIDetector.Smile is not null && Smile is not null) {
103103
keys.Add (CIDetector.Smile);
104-
values.Add (NSObject.FromObject (Smile.Value));
104+
values.Add (NSObject.FromObject (Smile.Value)!);
105105
}
106106
// AspectRation exists only in iOS8+, before this the field is null (and would throw if used)
107107
if (CIDetector.AspectRatio is not null && AspectRatio is not null) {

src/Foundation/DictionaryContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ protected void SetArrayValue<T> (NSString key, T []? values)
633633
if (NullCheckObjectAndRemoveKey (key, values)) {
634634
var nsValues = new NSObject [values.Length];
635635
for (var i = 0; i < values.Length; i++)
636-
nsValues [i] = NSObject.FromObject (values [i]);
636+
nsValues [i] = NSObject.FromObject (values [i])!;
637637
Dictionary [key] = NSArray.FromNSObjects (nsValues);
638638
}
639639
}

src/Foundation/NSAction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public NSActionDispatcher (Action action)
6464
[Register ("__MonoMac_NSSynchronizationContextDispatcher")]
6565
internal sealed class NSSynchronizationContextDispatcher : NSDispatcher {
6666
readonly SendOrPostCallback d;
67-
readonly object state;
67+
readonly object? state;
6868

69-
public NSSynchronizationContextDispatcher (SendOrPostCallback d, object state)
69+
public NSSynchronizationContextDispatcher (SendOrPostCallback d, object? state)
7070
{
7171
if (d is null)
7272
throw new ArgumentNullException (nameof (d));
@@ -149,7 +149,7 @@ internal sealed class NSAsyncSynchronizationContextDispatcher : NSAsyncDispatche
149149
SendOrPostCallback? d;
150150
object? state;
151151

152-
public NSAsyncSynchronizationContextDispatcher (SendOrPostCallback d, object state)
152+
public NSAsyncSynchronizationContextDispatcher (SendOrPostCallback d, object? state)
153153
{
154154
if (d is null)
155155
throw new ArgumentNullException (nameof (d));

0 commit comments

Comments
 (0)