@@ -283,6 +283,7 @@ static public NSArray FromStrings (IReadOnlyList<string> items)
283283 }
284284 }
285285
286+ #nullable enable
286287 /// <summary>Create an <see cref="NSArray" /> from the specified pointers.</summary>
287288 /// <param name="items">Array of pointers (to <see cref="NSObject" /> instances).</param>
288289 /// <remarks>If the <paramref name="items" /> array is null, an <see cref="ArgumentNullException" /> is thrown.</remarks>
@@ -293,24 +294,25 @@ static internal NSArray FromIntPtrs (IntPtr [] items)
293294
294295 unsafe {
295296 fixed ( IntPtr * valuesPtr = items )
296- return Runtime . GetNSObject < NSArray > ( NSArray . FromObjects ( ( IntPtr ) valuesPtr , items . Length ) ) ! ;
297+ return Runtime . GetNSObject < NSArray > ( NSArray . FromObjects ( ( IntPtr ) valuesPtr , items . Length ) ) ?? new NSArray ( ) ;
297298 }
298299 }
299300
300- static public NSArray FromIntPtrs ( NativeHandle [ ] vals )
301+ /// <summary>Create an <see cref="NSArray" /> from the specified pointers.</summary>
302+ /// <param name="vals">Array of pointers (to <see cref="NSObject" /> instances).</param>
303+ /// <remarks>If the <paramref name="vals" /> array is null, an <see cref="ArgumentNullException" /> is thrown.</remarks>
304+ public static NSArray FromIntPtrs ( NativeHandle [ ] vals )
301305 {
302306 if ( vals is null )
303- throw new ArgumentNullException ( "vals" ) ;
304- int n = vals . Length ;
305- IntPtr buf = Marshal . AllocHGlobal ( n * IntPtr . Size ) ;
306- for ( int i = 0 ; i < n ; i ++ )
307- Marshal . WriteIntPtr ( buf , i * IntPtr . Size , vals [ i ] ) ;
308-
309- NSArray arr = Runtime . GetNSObject < NSArray > ( NSArray . FromObjects ( buf , vals . Length ) ) ;
307+ throw new ArgumentNullException ( nameof ( vals ) ) ;
310308
311- Marshal . FreeHGlobal ( buf ) ;
312- return arr ;
309+ unsafe {
310+ fixed ( NativeHandle * valuesPtr = vals ) {
311+ return Runtime . GetNSObject < NSArray > ( NSArray . FromObjects ( ( IntPtr ) valuesPtr , vals . Length ) ) ?? new NSArray ( ) ;
312+ }
313+ }
313314 }
315+ #nullable disable
314316
315317 internal static nuint GetCount ( IntPtr handle )
316318 {
0 commit comments