diff --git a/docs/api/Foundation/NSObjectFlag.xml b/docs/api/Foundation/NSObjectFlag.xml
deleted file mode 100644
index 4d2eeee9ad5b..000000000000
--- a/docs/api/Foundation/NSObjectFlag.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
- Sentinel class used by the MonoTouch framework.
-
-
- The sole purpose for the NSObjectFlag class is to be used
- as a sentinel in the NSObject class hierarchy to ensure that the
- actual object initialization only happens in NSObject.
-
-
- When you chain your constructors using NSObjectFlag.Empty the
- only thing that will take place is the allocation of the
- object instance, no calls to any of the init: methods in base
- classes will be performed. If your code depends on this for
- initialization, you are responsible for calling the proper
- init method directly. For example:
-
-
-
-
-
-
- Alternatively, if you need a base class to initialize itself,
- you should call one of the other constructors that take some
- parameters.
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/api/Foundation/NSObservedChange.xml b/docs/api/Foundation/NSObservedChange.xml
deleted file mode 100644
index fd11971e4416..000000000000
--- a/docs/api/Foundation/NSObservedChange.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
- Changes that ocurred to an object being observed by Key-Value-Observing
-
- This class exposes the various components that were changes in a Key-Value-Observed property.
- These are merely accessors to the underlying NSDictionary that is provided to the method.
- Instances of this class are provided to your callback methods that you provide to .
- You can also create these objects if you have a dictionary that contains the keys from a key-value-observing change. For example if you override the method.
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/AppKit/NSColor.cs b/src/AppKit/NSColor.cs
index efd20e074bc4..d886ef6434bd 100644
--- a/src/AppKit/NSColor.cs
+++ b/src/AppKit/NSColor.cs
@@ -442,7 +442,7 @@ public void GetComponents (out nfloat [] components)
/// To be added.
/// To be added.
/// To be added.
- public override string ToString ()
+ public override string? ToString ()
{
try {
string name = this.ColorSpaceName;
diff --git a/src/CoreBluetooth/CBUUID.cs b/src/CoreBluetooth/CBUUID.cs
index 184f0dff17d3..9528f9b61fb4 100644
--- a/src/CoreBluetooth/CBUUID.cs
+++ b/src/CoreBluetooth/CBUUID.cs
@@ -110,7 +110,7 @@ public unsafe bool Equals (CBUUID? obj)
/// To be added.
/// To be added.
/// To be added.
- public override bool Equals (object obj)
+ public override bool Equals (object? obj)
{
return base.Equals (obj);
}
diff --git a/src/CoreFoundation/CFException.cs b/src/CoreFoundation/CFException.cs
index 8ded3146ce11..b60c80b7b051 100644
--- a/src/CoreFoundation/CFException.cs
+++ b/src/CoreFoundation/CFException.cs
@@ -144,7 +144,7 @@ public static CFException FromCFError (IntPtr cfErrorHandle, bool release)
using (var userInfo = new NSDictionary (cfUserInfo)) {
foreach (var i in userInfo) {
if (i.Key is not null)
- e.Data.Add (i.Key.ToString (), i.Value?.ToString ());
+ e.Data.Add (i.Key.ToString () ?? "", i.Value?.ToString () ?? "");
}
}
}
diff --git a/src/CoreImage/CIDetectorOptions.cs b/src/CoreImage/CIDetectorOptions.cs
index 857711acc3c8..f6314e7137d0 100644
--- a/src/CoreImage/CIDetectorOptions.cs
+++ b/src/CoreImage/CIDetectorOptions.cs
@@ -89,19 +89,19 @@ internal NSDictionary ToDictionary ()
// Tracking exists only in iOS6+, before this the field is null (and would throw if used)
if (CIDetector.Tracking is not null && TrackingEnabled is not null) {
keys.Add (CIDetector.Tracking);
- values.Add (NSObject.FromObject (TrackingEnabled.Value));
+ values.Add (NSObject.FromObject (TrackingEnabled.Value)!);
}
// EyeBlink exists only in iOS7+, before this the field is null (and would throw if used)
if (CIDetector.EyeBlink is not null && EyeBlink is not null) {
keys.Add (CIDetector.EyeBlink);
- values.Add (NSObject.FromObject (EyeBlink.Value));
+ values.Add (NSObject.FromObject (EyeBlink.Value)!);
}
// Smile exists only in iOS7+, before this the field is null (and would throw if used)
if (CIDetector.Smile is not null && Smile is not null) {
keys.Add (CIDetector.Smile);
- values.Add (NSObject.FromObject (Smile.Value));
+ values.Add (NSObject.FromObject (Smile.Value)!);
}
// AspectRation exists only in iOS8+, before this the field is null (and would throw if used)
if (CIDetector.AspectRatio is not null && AspectRatio is not null) {
diff --git a/src/Foundation/DictionaryContainer.cs b/src/Foundation/DictionaryContainer.cs
index 2957dd9cdff1..f373b9acb8eb 100644
--- a/src/Foundation/DictionaryContainer.cs
+++ b/src/Foundation/DictionaryContainer.cs
@@ -633,7 +633,7 @@ protected void SetArrayValue (NSString key, T []? values)
if (NullCheckObjectAndRemoveKey (key, values)) {
var nsValues = new NSObject [values.Length];
for (var i = 0; i < values.Length; i++)
- nsValues [i] = NSObject.FromObject (values [i]);
+ nsValues [i] = NSObject.FromObject (values [i])!;
Dictionary [key] = NSArray.FromNSObjects (nsValues);
}
}
diff --git a/src/Foundation/NSAction.cs b/src/Foundation/NSAction.cs
index a3a6d8666dd8..0772d991738a 100644
--- a/src/Foundation/NSAction.cs
+++ b/src/Foundation/NSAction.cs
@@ -64,9 +64,9 @@ public NSActionDispatcher (Action action)
[Register ("__MonoMac_NSSynchronizationContextDispatcher")]
internal sealed class NSSynchronizationContextDispatcher : NSDispatcher {
readonly SendOrPostCallback d;
- readonly object state;
+ readonly object? state;
- public NSSynchronizationContextDispatcher (SendOrPostCallback d, object state)
+ public NSSynchronizationContextDispatcher (SendOrPostCallback d, object? state)
{
if (d is null)
throw new ArgumentNullException (nameof (d));
@@ -149,7 +149,7 @@ internal sealed class NSAsyncSynchronizationContextDispatcher : NSAsyncDispatche
SendOrPostCallback? d;
object? state;
- public NSAsyncSynchronizationContextDispatcher (SendOrPostCallback d, object state)
+ public NSAsyncSynchronizationContextDispatcher (SendOrPostCallback d, object? state)
{
if (d is null)
throw new ArgumentNullException (nameof (d));
diff --git a/src/Foundation/NSObject2.cs b/src/Foundation/NSObject2.cs
index 6c25c77fbd8a..28f836cb090c 100644
--- a/src/Foundation/NSObject2.cs
+++ b/src/Foundation/NSObject2.cs
@@ -41,16 +41,67 @@
using CoreGraphics;
#endif
-// Disable until we get around to enable + fix any issues.
-#nullable disable
+#nullable enable
namespace Foundation {
- ///
- [SupportedOSPlatform ("ios")]
- [SupportedOSPlatform ("maccatalyst")]
- [SupportedOSPlatform ("macos")]
- [SupportedOSPlatform ("tvos")]
+ ///
+ /// Sentinel class.
+ ///
+ ///
+ ///
+ /// The sole purpose for the class is to be used
+ /// as a sentinel in the class hierarchy to ensure that the
+ /// actual object initialization only happens in .
+ ///
+ ///
+ /// When you chain your constructors using the
+ /// only thing that will take place is the allocation of the
+ /// object instance; no calls to any of the init: methods in base
+ /// classes will be performed. If your code depends on this for
+ /// initialization, you are responsible for calling the proper
+ /// init method directly. For example:
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Alternatively, if you need a base class to initialize itself,
+ /// you should call one of the other constructors that take some
+ /// parameters.
+ ///
+ ///
+ ///
+ ///
+ ///
public enum NSObjectFlag {
/// Sentinel instance.
Empty,
@@ -61,7 +112,7 @@ internal interface INSObjectFactory {
// The method will be implemented via custom linker step if the managed static registrar is used
// for NSObject subclasses which have an (NativeHandle) or (IntPtr) constructor.
[MethodImpl (MethodImplOptions.NoInlining)]
- virtual static NSObject _Xamarin_ConstructNSObject (NativeHandle handle) => null;
+ virtual static NSObject? _Xamarin_ConstructNSObject (NativeHandle handle) => null;
}
#if !COREBUILD
@@ -123,10 +174,6 @@ protected override bool ReleaseHandle ()
#if !COREBUILD
///
[ObjectiveCTrackedType]
- [SupportedOSPlatform ("ios")]
- [SupportedOSPlatform ("maccatalyst")]
- [SupportedOSPlatform ("macos")]
- [SupportedOSPlatform ("tvos")]
#endif
[StructLayout (LayoutKind.Sequential)]
public partial class NSObject : INativeObject
@@ -144,9 +191,10 @@ public partial class NSObject : INativeObject
static IntPtr selEncodeWithCoderHandle = Selector.GetHandle (selEncodeWithCoder);
#endif
- // replace older Mono[Touch|Mac]Assembly field (ease code sharing across platforms)
- /// To be added.
- /// To be added.
+ ///
+ /// Gets the assembly containing the platform-specific Foundation types.
+ ///
+ /// The assembly containing the platform-specific Foundation types.
public static readonly Assembly PlatformAssembly = typeof (NSObject).Assembly;
// This is exclusively for Mono
@@ -161,7 +209,6 @@ unsafe NativeHandle handle {
// safely from native code without having to make sure the GC doesn't move the memory around. Among
// other things, this means it's accessible from threads that has never seen/run managed code without
// having to attach those threads to to the managed runtime.
-#nullable enable
NSObjectDataHandle? data_handle;
internal unsafe NSObjectData* GetData ()
@@ -201,7 +248,6 @@ unsafe Flags flags {
get { return GetData ()->flags; }
set { GetData ()->flags = value; }
}
-#nullable disable
// This enum has a native counterpart in runtime.h
[Flags]
@@ -245,9 +291,10 @@ internal bool IsRegisteredToggleRef {
set { flags = value ? (flags | Flags.RegisteredToggleRef) : (flags & ~Flags.RegisteredToggleRef); }
}
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Gets or sets a value indicating whether this instance uses direct Objective-C binding.
+ ///
+ /// if this instance uses direct binding; otherwise, .
[DebuggerBrowsable (DebuggerBrowsableState.Never)]
[EditorBrowsable (EditorBrowsableState.Never)]
protected internal bool IsDirectBinding {
@@ -305,11 +352,16 @@ protected NSObject (NativeHandle handle, bool alloced)
Dispose (false);
}
- /// Releases the resources used by the NSObject object.
- ///
- /// The Dispose method releases the resources used by the NSObject class.
- /// Calling the Dispose method when the application is finished using the NSObject ensures that all external resources used by this managed object are released as soon as possible. Once developers have invoked the Dispose method, the object is no longer useful and developers should no longer make any calls to it. For more information on releasing resources see ``Cleaning up Unmananaged Resources'' at https://msdn.microsoft.com/en-us/library/498928w2.aspx
- ///
+ /// Releases the resources used by the object.
+ ///
+ /// The method releases the resources used by the class.
+ ///
+ /// Calling the method when the application is finished using the ensures that all
+ /// external resources used by this managed object are released as soon as possible. Once developers have invoked
+ /// the method, the object is no longer useful and developers should no longer make any calls to it.
+ /// For more information on releasing resources see Cleaning up unmanaged resources.
+ ///
+ ///
public void Dispose ()
{
Dispose (true);
@@ -329,7 +381,10 @@ internal static IntPtr CreateNSObject (IntPtr type_gchandle, IntPtr handle, Flag
}
// This function is called from native code before any constructors have executed.
- var type = (Type) Runtime.GetGCHandleTarget (type_gchandle);
+ var type = (Type?) Runtime.GetGCHandleTarget (type_gchandle);
+ if (type is null)
+ return IntPtr.Zero;
+
try {
var obj = (NSObject) RuntimeHelpers.GetUninitializedObject (type);
obj.handle = handle;
@@ -385,13 +440,12 @@ static void RegisterToggleReference (NSObject obj, IntPtr handle, bool isCustomT
-The class is not a custom type - it must wrap a framework class.
*/
/// Promotes a regular peer object (IsDirectBinding is true) into a toggleref object.
- ///
- /// This turns a regular peer object (one that has
- /// IsDirectBinding set to true) into a toggleref object. This
- /// is necessary when you are storing to a backing field whose
- /// objc_c semantics is not copy or retain. This is an internal
- /// method.
- ///
+ ///
+ /// This turns a regular peer object (one that has set to true)
+ /// into a toggleref object. This is necessary when storing managed state (for instance into
+ /// a backing field), so that the managed peer isn't collected by the GC before the native object
+ /// is freed. This is an internal method.
+ ///
[EditorBrowsable (EditorBrowsableState.Never)]
protected void MarkDirty ()
{
@@ -483,7 +537,7 @@ static bool IsProtocol (Type type, IntPtr protocol)
{
while (type != typeof (NSObject) && type is not null) {
var attrs = type.GetCustomAttributes (typeof (ProtocolAttribute), false);
- var protocolAttribute = (ProtocolAttribute) (attrs.Length > 0 ? attrs [0] : null);
+ var protocolAttribute = (ProtocolAttribute?) (attrs.Length > 0 ? attrs [0] : null);
if (protocolAttribute is not null && !protocolAttribute.IsInformal) {
string name;
@@ -491,7 +545,7 @@ static bool IsProtocol (Type type, IntPtr protocol)
name = protocolAttribute.Name;
} else {
attrs = type.GetCustomAttributes (typeof (RegisterAttribute), false);
- var registerAttribute = (RegisterAttribute) (attrs.Length > 0 ? attrs [0] : null);
+ var registerAttribute = (RegisterAttribute?) (attrs.Length > 0 ? attrs [0] : null);
if (registerAttribute is not null && !string.IsNullOrEmpty (registerAttribute.Name)) {
name = registerAttribute.Name;
} else {
@@ -503,7 +557,10 @@ static bool IsProtocol (Type type, IntPtr protocol)
if (proto != IntPtr.Zero && proto == protocol)
return true;
}
- type = type.BaseType;
+ var baseType = type.BaseType;
+ if (baseType is null)
+ return false;
+ type = baseType;
}
return false;
@@ -559,7 +616,7 @@ public virtual bool ConformsToProtocol (NativeHandle protocol)
var classHandle = ClassHandle;
lock (Runtime.protocol_cache) {
ref var map = ref CollectionsMarshal.GetValueRefOrAddDefault (Runtime.protocol_cache, classHandle, out var exists);
- if (!exists)
+ if (!exists || map is null)
map = new ();
ref var result = ref CollectionsMarshal.GetValueRefOrAddDefault (map, protocol, out exists);
if (!exists)
@@ -665,15 +722,15 @@ public NSObject DangerousAutorelease ()
return this;
}
- /// Handle used to represent the methods in the base class for this NSObject.
- /// An opaque pointer, represents an Objective-C objc_super object pointing to our base class.
- ///
- /// This property is used to access members of a base class.
- /// This is typically used when you call any of the Messaging
- /// methods to invoke methods that were implemented in your base
- /// class, instead of invoking the implementation in the current
- /// class.
- ///
+ /// Handle used to represent the methods in the base class for this .
+ /// An opaque pointer, represents an Objective-C objc_super object pointing to our base class.
+ ///
+ /// This property is used to access members of a base class.
+ /// This is typically used when you call any of the Messaging
+ /// methods to invoke methods that were implemented in your base
+ /// class, instead of invoking the implementation in the current
+ /// class.
+ ///
[EditorBrowsable (EditorBrowsableState.Never)]
public NativeHandle SuperHandle {
get {
@@ -685,8 +742,8 @@ public NativeHandle SuperHandle {
}
/// Handle (pointer) to the unmanaged object representation.
- /// A pointer
- /// This IntPtr is a handle to the underlying unmanaged representation for this object.
+ /// A pointer.
+ /// This is a handle to the underlying unmanaged representation for this object.
[EditorBrowsable (EditorBrowsableState.Never)]
public NativeHandle Handle {
get { return handle; }
@@ -746,67 +803,72 @@ private bool AllocIfNeeded ()
return false;
}
- private void InvokeOnMainThread (Selector sel, NSObject obj, bool wait)
+ private void InvokeOnMainThread (Selector sel, NSObject? obj, bool wait)
{
Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (this.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone), sel.Handle, obj.GetHandle (), wait ? (byte) 1 : (byte) 0);
GC.KeepAlive (sel);
GC.KeepAlive (obj);
}
+ /// Invokes asynchronously the specified code on the main UI thread.
/// Selector to invoke
- /// Object in which the selector is invoked
- /// Invokes asynchrously the specified code on the main UI thread.
- ///
- ///
- /// You use this method from a thread to invoke the code in
- /// the specified object that is exposed with the specified
- /// selector in the UI thread. This is required for most
- /// operations that affect UIKit or AppKit as neither one of
- /// those APIs is thread safe.
- ///
- ///
- /// The code is executed when the main thread goes back to its
- /// main loop for processing events.
- ///
- ///
- /// Unlike
- /// this method merely queues the invocation and returns
- /// immediately to the caller.
- ///
- ///
- public void BeginInvokeOnMainThread (Selector sel, NSObject obj)
+ /// Object in which the selector is invoked
+ ///
+ ///
+ /// You use this method from a thread to invoke the code in
+ /// the specified object that is exposed with the specified
+ /// selector in the UI thread. This is required for most
+ /// operations that affect UIKit or AppKit as neither one of
+ /// those APIs is thread safe.
+ ///
+ ///
+ /// The code is executed when the main thread goes back to its
+ /// main loop for processing events.
+ ///
+ ///
+ /// Unlike
+ /// this method merely queues the invocation and returns
+ /// immediately to the caller.
+ ///
+ ///
+ public void BeginInvokeOnMainThread (Selector sel, NSObject? obj)
{
InvokeOnMainThread (sel, obj, false);
}
+ /// Invokes synchronously the specified code on the main UI thread.
/// Selector to invoke
- /// Object in which the selector is invoked
- /// Invokes synchrously the specified code on the main UI thread.
- ///
- ///
- /// You use this method from a thread to invoke the code in
- /// the specified object that is exposed with the specified
- /// selector in the UI thread. This is required for most
- /// operations that affect UIKit or AppKit as neither one of
- /// those APIs is thread safe.
- ///
- ///
- /// The code is executed when the main thread goes back to its
- /// main loop for processing events.
- ///
- ///
- /// Unlike
- /// this method waits for the main thread to execute the method, and does not return until the code pointed by action has completed.
- ///
- ///
- public void InvokeOnMainThread (Selector sel, NSObject obj)
+ /// Object in which the selector is invoked
+ ///
+ ///
+ /// You use this method from a thread to invoke the code in
+ /// the specified object that is exposed with the specified
+ /// selector in the UI thread. This is required for most
+ /// operations that affect UIKit or AppKit as neither one of
+ /// those APIs is thread safe.
+ ///
+ ///
+ /// The code is executed when the main thread goes back to its
+ /// main loop for processing events.
+ ///
+ ///
+ /// Unlike
+ /// this method waits for the main thread to execute the method, and does not return until the code pointed by action has completed.
+ ///
+ ///
+ public void InvokeOnMainThread (Selector sel, NSObject? obj)
{
InvokeOnMainThread (sel, obj, true);
}
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Invokes the specified action asynchronously on the main UI thread.
+ ///
+ /// The action to invoke.
+ ///
+ /// This method queues the action to be executed when the main thread goes back to its
+ /// main loop for processing events. The method returns immediately to the caller.
+ ///
public void BeginInvokeOnMainThread (Action action)
{
var d = new NSAsyncActionDispatcher (action);
@@ -815,7 +877,7 @@ public void BeginInvokeOnMainThread (Action action)
GC.KeepAlive (d);
}
- internal void BeginInvokeOnMainThread (System.Threading.SendOrPostCallback cb, object state)
+ internal void BeginInvokeOnMainThread (System.Threading.SendOrPostCallback cb, object? state)
{
var d = new NSAsyncSynchronizationContextDispatcher (cb, state);
Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone),
@@ -823,9 +885,13 @@ internal void BeginInvokeOnMainThread (System.Threading.SendOrPostCallback cb, o
GC.KeepAlive (d);
}
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Invokes the specified action synchronously on the main UI thread.
+ ///
+ /// The action to invoke.
+ ///
+ /// This method waits for the main thread to execute the action, and does not return until the action has completed.
+ ///
public void InvokeOnMainThread (Action action)
{
using (var d = new NSActionDispatcher (action)) {
@@ -834,7 +900,7 @@ public void InvokeOnMainThread (Action action)
}
}
- internal void InvokeOnMainThread (System.Threading.SendOrPostCallback cb, object state)
+ internal void InvokeOnMainThread (System.Threading.SendOrPostCallback cb, object? state)
{
using (var d = new NSSynchronizationContextDispatcher (cb, state)) {
Messaging.void_objc_msgSend_NativeHandle_NativeHandle_bool (d.Handle, Selector.GetHandle (Selector.PerformSelectorOnMainThreadWithObjectWaitUntilDone),
@@ -843,13 +909,13 @@ internal void InvokeOnMainThread (System.Threading.SendOrPostCallback cb, object
}
///
- public static NSObject FromObject (object obj)
+ public static NSObject? FromObject (object? obj)
{
if (obj is null)
return NSNull.Null;
var t = obj.GetType ();
- if (t == typeof (NSObject) || t.IsSubclassOf (typeof (NSObject)))
- return (NSObject) obj;
+ if (obj is NSObject nsobj)
+ return nsobj;
switch (Type.GetTypeCode (t)) {
case TypeCode.Boolean:
@@ -912,9 +978,9 @@ public static NSObject FromObject (object obj)
#endif
// last chance for types like CGPath, CGColor... that are not NSObject but are CFObject
// see https://bugzilla.xamarin.com/show_bug.cgi?id=8458
- INativeObject native = (obj as INativeObject);
+ var native = (obj as INativeObject);
if (native is not null) {
- NSObject result = Runtime.GetNSObject (native.Handle);
+ var result = Runtime.GetNSObject (native.Handle);
GC.KeepAlive (native);
return result;
}
@@ -922,10 +988,19 @@ public static NSObject FromObject (object obj)
}
}
+ ///
+ /// Sets the value for the property identified by a given key path to a given value.
+ ///
+ /// A handle to the value to set.
+ /// A key path of the form relationship.property (with one or more relationships); for example "department.name" or "department.manager.lastName".
+ ///
+ /// This method is useful for setting a value for a property that can be reached by following a key path.
+ /// The key path is a series of property names separated by periods.
+ ///
public void SetValueForKeyPath (NativeHandle handle, NSString keyPath)
{
if (keyPath is null)
- throw new ArgumentNullException ("keyPath");
+ throw new ArgumentNullException (nameof (keyPath));
if (IsDirectBinding) {
ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle_NativeHandle (this.Handle, Selector.GetHandle ("setValue:forKeyPath:"), handle, keyPath.Handle);
GC.KeepAlive (keyPath);
@@ -939,8 +1014,8 @@ public void SetValueForKeyPath (NativeHandle handle, NSString keyPath)
// a correct implementation of GetHashCode / Equals. We default to Object.GetHashCode (like classic)
/// Generates a hash code for the current instance.
- /// A int containing the hash code for this instance.
- /// The algorithm used to generate the hash code is unspecified.
+ /// A int containing the hash code for this instance.
+ /// The algorithm used to generate the hash code is unspecified.
public override int GetHashCode ()
{
if (!IsDirectBinding)
@@ -949,11 +1024,16 @@ public override int GetHashCode ()
return GetNativeHash ().GetHashCode ();
}
- /// To be added.
- /// To be added.
- /// To be added.
- /// To be added.
- public override bool Equals (object obj)
+ ///
+ /// Determines whether the specified object is equal to the current .
+ ///
+ /// The object to compare with the current object.
+ /// if the specified object is equal to the current object; otherwise, .
+ ///
+ /// For direct bindings, this method uses the Objective-C isEqual: method.
+ /// For non-direct bindings, this method uses reference equality.
+ ///
+ public override bool Equals (object? obj)
{
var o = obj as NSObject;
if (o is null)
@@ -969,38 +1049,41 @@ public override bool Equals (object obj)
}
// IEquatable
- /// To be added.
- /// To be added.
- /// To be added.
- /// To be added.
- public bool Equals (NSObject obj) => Equals ((object) obj);
+ ///
+ /// Determines whether the specified is equal to the current .
+ ///
+ /// The object to compare with the current object.
+ /// if the specified object is equal to the current object; otherwise, .
+ ///
+ /// For direct bindings, this method uses the Objective-C isEqual: method.
+ /// For non-direct bindings, this method uses reference equality.
+ ///
+ public bool Equals (NSObject? obj) => Equals ((object?) obj);
/// Returns a string representation of the value of the current instance.
- ///
- ///
- ///
- ///
- public override string ToString ()
+ public override string? ToString ()
{
if (disposed)
return base.ToString ();
return Description ?? base.ToString ();
}
- /// To be added.
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Invokes the specified action after the specified delay.
+ ///
+ /// The action to invoke.
+ /// The delay in seconds.
public virtual void Invoke (Action action, double delay)
{
var d = new NSAsyncActionDispatcher (action);
d.PerformSelector (NSDispatcher.Selector, null, delay);
}
- /// To be added.
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Invokes the specified action after the specified delay.
+ ///
+ /// The action to invoke.
+ /// The delay as a .
public virtual void Invoke (Action action, TimeSpan delay)
{
var d = new NSAsyncActionDispatcher (action);
@@ -1029,7 +1112,6 @@ protected virtual void Dispose (bool disposing)
}
}
-#nullable enable
void RecreateDataHandle ()
{
// OK, this code is _weird_.
@@ -1080,7 +1162,6 @@ void RecreateDataHandle ()
// Don't dispose previous_data, because another thread might be referencing it, and trying to access its pointer - which is still valid.
// The GC will dispose of previous_data when its not accessible anymore.
}
-#nullable disable
[Register ("__NSObject_Disposer")]
[Preserve (AllMembers = true)]
@@ -1155,8 +1236,8 @@ static void Drain (NSObject ctx)
[Register ("__XamarinObjectObserver")]
class Observer : NSObject {
- WeakReference obj;
- Action cback;
+ WeakReference? obj;
+ Action? cback;
NSString key;
public Observer (NSObject obj, NSString key, Action observer)
@@ -1174,7 +1255,7 @@ public Observer (NSObject obj, NSString key, Action observer)
public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
if (keyPath == key && context == Handle)
- cback (new NSObservedChange (change));
+ cback!.Invoke (new NSObservedChange (change));
else
base.ObserveValue (keyPath, ofObject, change, context);
}
@@ -1182,9 +1263,8 @@ public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictio
protected override void Dispose (bool disposing)
{
if (disposing) {
- NSObject target;
if (obj is not null) {
- target = (NSObject) obj.Target;
+ var target = (NSObject?) obj.Target;
if (target is not null)
target.RemoveObserver (this, key, Handle);
}
@@ -1211,10 +1291,14 @@ public IDisposable AddObserver (NSString key, NSKeyValueObservingOptions options
return o;
}
- /// To be added.
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Allocates an uninitialized instance of the specified class.
+ ///
+ /// The class to allocate.
+ /// A new uninitialized instance.
+ ///
+ /// This method should typically be followed by a call to an init method to properly initialize the object.
+ ///
[EditorBrowsable (EditorBrowsableState.Never)]
public static NSObject Alloc (Class kls)
{
@@ -1223,8 +1307,12 @@ public static NSObject Alloc (Class kls)
return new NSObject (h, true);
}
- /// To be added.
- /// To be added.
+ ///
+ /// Initializes the object by calling the Objective-C init method.
+ ///
+ ///
+ /// This method should only be called on objects that have been allocated but not yet initialized.
+ ///
[EditorBrowsable (EditorBrowsableState.Never)]
public void Init ()
{
@@ -1234,16 +1322,17 @@ public void Init ()
handle = Messaging.IntPtr_objc_msgSend (handle, Selector.GetHandle ("init"));
}
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Invokes the specified action on a background thread.
+ ///
+ /// The action to invoke.
public static void InvokeInBackground (Action action)
{
// using the parameterized Thread.Start to avoid capturing
// the 'action' parameter (it'll needlessly create an extra
// object).
new System.Threading.Thread ((v) => {
- ((Action) v) ();
+ ((Action) v!) ();
}) {
IsBackground = true,
}.Start (action);
@@ -1252,34 +1341,56 @@ public static void InvokeInBackground (Action action)
}
#if !COREBUILD
- ///
- [SupportedOSPlatform ("ios")]
- [SupportedOSPlatform ("maccatalyst")]
- [SupportedOSPlatform ("macos")]
- [SupportedOSPlatform ("tvos")]
+ ///
+ /// Changes that occurred to an object being observed by Key-Value-Observing.
+ ///
+ ///
+ /// This class exposes the various components that were changed in a Key-Value-Observed property.
+ /// These are merely accessors to the underlying that is provided to the method.
+ /// Instances of this class are provided to your callback methods that you provide to .
+ /// You can also create these objects if you have a dictionary that contains the keys from a key-value-observing change. For example if you override the method.
+ ///
+ ///
+ ///
+ ///
public class NSObservedChange {
NSDictionary dict;
- /// To be added.
- /// To be added.
- /// To be added.
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The dictionary containing the change information.
public NSObservedChange (NSDictionary source)
{
dict = source;
}
/// Records the kind of change that was done to the property.
- /// The current state of the changes being reported.
- /// You can use the value of this property to determine which information is available on the other properties of this class.
+ /// The current state of the changes being reported.
+ /// You can use the value of this property to determine which information is available on the other properties of this class.
public NSKeyValueChange Change {
get {
- var n = (NSNumber) dict [NSObject.ChangeKindKey];
- return (NSKeyValueChange) n.Int32Value;
+ var n = (NSNumber?) dict [NSObject.ChangeKindKey];
+ return (NSKeyValueChange) (n?.Int32Value ?? 0);
}
}
/// The new value being set on the observed property.
/// For this property to have a value, the options passed to method should contain the value New.
- public NSObject NewValue {
+ public NSObject? NewValue {
get {
return dict [NSObject.ChangeNewKey];
}
@@ -1288,18 +1399,18 @@ public NSObject NewValue {
/// The previous value on the observed property.
/// The old value.
/// For this property to have a value, the options passed to method should contain the value .
- public NSObject OldValue {
+ public NSObject? OldValue {
get {
return dict [NSObject.ChangeOldKey];
}
}
/// The indexes of the objects that were added, removed or changed.
- /// To be added.
- /// This value is set if the Change property is one of
- public NSIndexSet Indexes {
+ /// An containing the indexes, or if not applicable.
+ /// This value is set if the Change property is either , or .
+ public NSIndexSet? Indexes {
get {
- return (NSIndexSet) dict [NSObject.ChangeIndexesKey];
+ return (NSIndexSet?) dict [NSObject.ChangeIndexesKey];
}
}
diff --git a/src/Foundation/NSOrderedSet.cs b/src/Foundation/NSOrderedSet.cs
index 179c8fe83371..e24bf7965c16 100644
--- a/src/Foundation/NSOrderedSet.cs
+++ b/src/Foundation/NSOrderedSet.cs
@@ -219,9 +219,12 @@ public override int GetHashCode ()
/// Determines whether the ordered set contains the specified object.
/// The object to locate in the ordered set.
/// if the ordered set contains the specified object; otherwise, .
- public bool Contains (object obj)
+ public bool Contains (object? obj)
{
- return Contains (NSObject.FromObject (obj));
+ var nsobj = NSObject.FromObject (obj);
+ if (nsobj is null)
+ return false;
+ return Contains (nsobj);
}
}
diff --git a/src/Foundation/NSSet.cs b/src/Foundation/NSSet.cs
index bcdc81ea2c79..c24e2918bd16 100644
--- a/src/Foundation/NSSet.cs
+++ b/src/Foundation/NSSet.cs
@@ -168,9 +168,12 @@ IEnumerator IEnumerable.GetEnumerator ()
/// Determines whether the set contains the specified object.
/// The object to locate in the set.
/// if the set contains the specified object; otherwise, .
- public bool Contains (object obj)
+ public bool Contains (object? obj)
{
- return Contains (NSObject.FromObject (obj));
+ var nsobj = NSObject.FromObject (obj);
+ if (nsobj is null)
+ return false;
+ return Contains (nsobj);
}
}
}
diff --git a/src/Foundation/NSString.cs b/src/Foundation/NSString.cs
index b918dd5cd818..c16bbc61d28b 100644
--- a/src/Foundation/NSString.cs
+++ b/src/Foundation/NSString.cs
@@ -264,7 +264,7 @@ public static NSString LocalizedFormat (NSString format, params object [] args)
int argc = args.Length;
var nso = new NSObject [argc];
for (int i = 0; i < argc; i++)
- nso [i] = NSObject.FromObject (args [i]);
+ nso [i] = NSObject.FromObject (args [i])!;
return LocalizedFormat (format, nso);
}
diff --git a/src/Foundation/NSUrl.cs b/src/Foundation/NSUrl.cs
index 8a8094036084..b3196dc70bfb 100644
--- a/src/Foundation/NSUrl.cs
+++ b/src/Foundation/NSUrl.cs
@@ -100,7 +100,7 @@ public NSUrl MakeRelative (string url)
///
///
///
- public override string ToString ()
+ public override string? ToString ()
{
return AbsoluteString ?? base.ToString ();
}
diff --git a/src/Foundation/NSUrlRequest.cs b/src/Foundation/NSUrlRequest.cs
index d70b3a924422..b03b55bf8488 100644
--- a/src/Foundation/NSUrlRequest.cs
+++ b/src/Foundation/NSUrlRequest.cs
@@ -33,7 +33,7 @@ namespace Foundation {
public partial class NSUrlRequest {
/// Returns a string representation of the value of the current instance.
/// The absolute string of the if it is not , otherwise the base class string representation.
- public override string ToString ()
+ public override string? ToString ()
{
return Url?.AbsoluteString ?? base.ToString ();
}
diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt
index 95168f0ae3d2..304a5515b88e 100644
--- a/tests/cecil-tests/Documentation.KnownFailures.txt
+++ b/tests/cecil-tests/Documentation.KnownFailures.txt
@@ -11945,7 +11945,6 @@ M:Foundation.NSObject.RemoveObserver(Foundation.NSObject,System.String)
M:Foundation.NSObject.SetDefaultPlaceholder(Foundation.NSObject,Foundation.NSObject,Foundation.NSString)
M:Foundation.NSObject.SetNilValueForKey(Foundation.NSString)
M:Foundation.NSObject.SetValueForKeyPath(Foundation.NSObject,Foundation.NSString)
-M:Foundation.NSObject.SetValueForKeyPath(ObjCRuntime.NativeHandle,Foundation.NSString)
M:Foundation.NSObject.SetValueForUndefinedKey(Foundation.NSObject,Foundation.NSString)
M:Foundation.NSObject.SetValuesForKeysWithDictionary(Foundation.NSDictionary)
M:Foundation.NSObject.Unbind(Foundation.NSString)