diff --git a/src/Foundation/DictionaryContainer.cs b/src/Foundation/DictionaryContainer.cs index 76b82f406d5e..2ded6c0e7825 100644 --- a/src/Foundation/DictionaryContainer.cs +++ b/src/Foundation/DictionaryContainer.cs @@ -215,7 +215,7 @@ bool TryGetNativeValue (NativeHandle key, out NativeHandle value) if (!TryGetNativeValue (key, out var value)) return null; - return NSArray.ArrayFromHandleFunc (value, creator); + return NSArray.ArrayFromHandleDropNullElements (value, (v) => creator (v), NSNullBehavior.DropIfIncompatible); } /// Retrieves the array associeted with . @@ -226,7 +226,7 @@ bool TryGetNativeValue (NativeHandle key, out NativeHandle value) if (!TryGetNativeValue (key, out var value)) return null; - return NSArray.ArrayFromHandleFunc (value, (handle) => Create (handle)!); + return NSArray.ArrayFromHandleDropNullElements (value, (handle) => Create (handle)!, NSNullBehavior.DropIfIncompatible); } /// Returns the nullable associated with the specified . diff --git a/src/Foundation/NSArray.cs b/src/Foundation/NSArray.cs index 9689a39ae923..212f775c3c9d 100644 --- a/src/Foundation/NSArray.cs +++ b/src/Foundation/NSArray.cs @@ -686,6 +686,18 @@ static bool TryGetItem (NativeHandle elementHandle, Converter (handle, (h) => Runtime.GetINativeObject (h, false)!, nsNullElementBehavior, releaseHandle)!; } + /// Returns a strongly-typed C# array from a handle to an NSArray, dropping null elements. + /// Parameter type, determines the kind of array returned. + /// Pointer (handle) to the unmanaged object. + /// A delegate to convert a native handle to an object of type T. + /// How to handle null and NSNull elements in the native array. + /// Whether the native NSArray instance should be released before returning or not. + /// A C# array with the values (excluding null elements). Returns if the handle is . + internal static T []? ArrayFromHandleDropNullElements (NativeHandle handle, Converter createObject, NSNullBehavior nsNullElementBehavior, bool releaseHandle = false) + { + return ArrayFromHandle (handle, createObject, nsNullElementBehavior, releaseHandle)!; + } + /// Returns a strongly-typed C# array from a handle to an NSArray, dropping null elements and guaranteeing a non-null return value. /// Parameter type, determines the kind of array returned. /// Pointer (handle) to the unmanaged object. @@ -832,36 +844,38 @@ internal static T [] ToNonNullArrayDropNullElements (NSArray? weakArray) wher } } -#nullable disable - // Used when we need to provide our constructor - /// Parameter type, determines the kind of array returned. - /// Pointer (handle) to the unmanaged object. - /// To be added. - /// Returns a strongly-typed C# array of the parametrized type from a handle to an NSArray. - /// An C# array with the values. + /// Creates a strongly-typed C# array from a handle to an , using a custom factory function. + /// The element type for the returned array. + /// Pointer (handle) to the unmanaged object. + /// A factory function that creates an instance of from a native handle. + /// A C# array with the values, or if is . /// - /// Use this method to get a set of NSObject arrays from a handle to an NSArray. Instead of wrapping the results in NSObjects, the code invokes your method to create the return value. - /// - /// (someHandle, (x) => (int) x); + /// + /// Instead of wrapping the results in instances, + /// this method invokes for each element to create the return value. + /// + /// + /// (someHandle, (x) => (int) x); /// ]]> - /// - /// - static public T [] ArrayFromHandleFunc (NativeHandle handle, Func createObject) + /// + /// + public static T? []? ArrayFromHandleFunc (NativeHandle handle, Func createObject) { return ArrayFromHandle (handle, (v) => createObject (v)); } - /// Create a managed array from a pointer to a native NSArray instance. - /// The pointer to the native NSArray instance. - /// A callback that returns an instance of the type T for a given pointer (for an element in the NSArray). - /// Whether the native NSArray instance should be released before returning or not. - public static T [] ArrayFromHandleFunc (NativeHandle handle, Func createObject, bool releaseHandle) + /// Creates a strongly-typed C# array from a handle to an , using a custom factory function. + /// The element type for the returned array. + /// Pointer (handle) to the unmanaged object. + /// A factory function that creates an instance of from a native handle. + /// Whether the native instance should be released before returning or not. + /// A C# array with the values, or if is . + public static T? []? ArrayFromHandleFunc (NativeHandle handle, Func createObject, bool releaseHandle) { return ArrayFromHandle (handle, (v) => createObject (v), releaseHandle); } -#nullable enable /// Creates a managed array from a pointer to a native NSArray of NSDictionary objects, dropping null and NSNull elements. /// The type of objects to create from the dictionaries. /// The pointer to the native NSArray instance containing NSDictionary objects. diff --git a/src/Foundation/NSUrlSessionConfiguration.cs b/src/Foundation/NSUrlSessionConfiguration.cs index b6bcb2ba8441..04afa208f39c 100644 --- a/src/Foundation/NSUrlSessionConfiguration.cs +++ b/src/Foundation/NSUrlSessionConfiguration.cs @@ -70,16 +70,17 @@ public static NSUrlSessionConfiguration CreateBackgroundSessionConfiguration (st return config; } + /// Gets or sets the proxy configurations for this session. + /// An array of objects representing the proxy configurations. [SupportedOSPlatform ("ios17.0")] [SupportedOSPlatform ("macos14.0")] [SupportedOSPlatform ("maccatalyst17.0")] [SupportedOSPlatform ("tvos17.0")] public NWProxyConfig [] ProxyConfigurations { - get => NSArray.ArrayFromHandleFunc (_ProxyConfigurations, handle => new NWProxyConfig (handle, owns: false)); + get => NSArray.NonNullArrayFromHandleDropNullElements (_ProxyConfigurations, handle => new NWProxyConfig (handle, owns: false)); set { - var arr = NSArray.FromNSObjects (value); - _ProxyConfigurations = arr.Handle; - GC.KeepAlive (arr); + using var arr = NSArray.FromNSObjects (value); + _ProxyConfigurations = arr.GetHandle (); } } diff --git a/src/PdfKit/PdfAnnotation.cs b/src/PdfKit/PdfAnnotation.cs index 50b403680038..a8cc8843a518 100644 --- a/src/PdfKit/PdfAnnotation.cs +++ b/src/PdfKit/PdfAnnotation.cs @@ -76,30 +76,22 @@ public PdfAnnotationKey AnnotationType { set { Type = value.GetConstant ()!; } } - /// To be added. - /// To be added. - /// To be added. + /// Gets or sets the points defining the quadrilateral bounds of the annotation. + /// An array of values representing the quadrilateral vertices, or . [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("ios")] [SupportedOSPlatform ("maccatalyst")] [SupportedOSPlatform ("tvos18.2")] - public CGPoint [] QuadrilateralPoints { + public CGPoint []? QuadrilateralPoints { get { - return NSArray.ArrayFromHandleFunc (_QuadrilateralPoints, (v) => { + return NSArray.ArrayFromHandle (_QuadrilateralPoints, (v) => { using (var value = new NSValue (v)) return value.CGPointValue; }); } set { - if (value is null) { - _QuadrilateralPoints = IntPtr.Zero; - } else { - using (var arr = new NSMutableArray ()) { - for (int i = 0; i < value.Length; i++) - arr.Add (NSValue.FromCGPoint (value [i])); - _QuadrilateralPoints = arr.Handle; - } - } + using var arr = NSArray.FromNSObjects ((element) => NSValue.FromCGPoint (element), value); + _QuadrilateralPoints = arr.GetHandle (); } } } diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt index cad51eed565b..5ae03ad8d051 100644 --- a/tests/cecil-tests/Documentation.KnownFailures.txt +++ b/tests/cecil-tests/Documentation.KnownFailures.txt @@ -21062,7 +21062,6 @@ P:Foundation.NSUbiquitousKeyValueStoreChangeEventArgs.ChangedKeys P:Foundation.NSUbiquitousKeyValueStoreChangeEventArgs.ChangeReason P:Foundation.NSUndoManagerCloseUndoGroupEventArgs.Discardable P:Foundation.NSUrlAuthenticationChallenge.SenderObject -P:Foundation.NSUrlSessionConfiguration.ProxyConfigurations P:Foundation.NSUrlSessionConfiguration.SessionType P:Foundation.NSUrlSessionConfiguration.StrongConnectionProxyDictionary P:Foundation.NSUrlSessionHandler.AllowsCellularAccess