Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AudioUnit/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public AudioComponentInfo []? ComponentList {
}
set {
using var nameHandle = new TransientCFString (Name);
using var array = NSArray.FromNSObjects (h => h.Dictionary, value);
using var array = NSArray.FromNSObjects (h => h?.Dictionary, value);
var result = (AudioConverterError) AudioUnitExtensionSetComponentList (nameHandle, array.GetHandle ());
switch (result) {
case AudioConverterError.None:
Expand Down
287 changes: 189 additions & 98 deletions src/Foundation/NSArray.cs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/Foundation/NSDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public partial class NSDictionary : NSObject, IDictionary, IDictionary<NSObject,
/// ]]></code>
/// </example>
/// </remarks>
public NSDictionary (NSObject first, NSObject second, params NSObject [] args) : this (PickOdd (second, args), PickEven (first, args))
public NSDictionary (NSObject? first, NSObject? second, params NSObject? [] args) : this (PickOdd (second, args), PickEven (first, args))
{
}

Expand Down Expand Up @@ -87,21 +87,21 @@ internal NSDictionary (NativeHandle handle, bool owns) : base (handle, owns)
{
}

internal static NSArray PickEven (NSObject f, NSObject [] args)
internal static NSArray PickEven (NSObject? f, NSObject? [] args)
{
int al = args.Length;
if ((al % 2) != 0)
throw new ArgumentException ("The arguments to NSDictionary should be a multiple of two", "args");
var ret = new NSObject [1 + al / 2];
var ret = new NSObject? [1 + al / 2];
ret [0] = f;
for (int i = 0, target = 1; i < al; i += 2)
ret [target++] = args [i];
return NSArray.FromNSObjects (ret);
}

internal static NSArray PickOdd (NSObject f, NSObject [] args)
internal static NSArray PickOdd (NSObject? f, NSObject? [] args)
{
var ret = new NSObject [1 + args.Length / 2];
var ret = new NSObject? [1 + args.Length / 2];
ret [0] = f;
for (int i = 1, target = 1; i < args.Length; i += 2)
ret [target++] = args [i];
Expand Down
6 changes: 3 additions & 3 deletions src/Foundation/NSDictionary_2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal static bool ValidateKeysAndValues (TKey [] keys, TValue [] values)
return true;
}

NSDictionary (TKey [] keys, TValue [] values, bool validation)
NSDictionary (TKey? [] keys, TValue? [] values, bool validation)
: base (NSArray.FromNSObjects (values), NSArray.FromNSObjects (keys))
{
}
Expand All @@ -137,7 +137,7 @@ public NSDictionary (TKey [] keys, TValue [] values)
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public NSDictionary (TKey key, TValue value)
public NSDictionary (TKey? key, TValue? value)
: base (NSArray.FromNSObjects (value), NSArray.FromNSObjects (key))
{
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public TValue [] ObjectsForKeys (TKey [] keys, TValue marker)
return [];

using (var pool = new NSAutoreleasePool ()) {
var keysArray = NSArray.From<TKey> (keys);
var keysArray = NSArray.FromNativeObjects<TKey> (keys);
var result = NSArray.ArrayFromHandle<TValue> (_ObjectsForKeys (keysArray.Handle, marker.Handle));
GC.KeepAlive (keysArray);
GC.KeepAlive (marker);
Expand Down
4 changes: 2 additions & 2 deletions src/Foundation/NSMutableDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class NSMutableDictionary : NSDictionary, IDictionary, IDictionar
/// <returns>A new mutable dictionary containing the specified objects and keys.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="objects"/> or <paramref name="keys"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">Thrown when the arrays have different sizes.</exception>
public static NSMutableDictionary FromObjectsAndKeys (NSObject [] objects, NSObject [] keys)
public static NSMutableDictionary FromObjectsAndKeys (NSObject? [] objects, NSObject? [] keys)
{
if (!ValidateFromObjectsAndKeys (objects, keys))
return new NSMutableDictionary ();
Expand Down Expand Up @@ -68,7 +68,7 @@ public static NSMutableDictionary FromObjectsAndKeys (object [] objects, object
/// <returns>A new mutable dictionary containing the specified objects and keys.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="objects"/> or <paramref name="keys"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="count"/> is invalid.</exception>
public static NSMutableDictionary FromObjectsAndKeys (NSObject [] objects, NSObject [] keys, nint count)
public static NSMutableDictionary FromObjectsAndKeys (NSObject? [] objects, NSObject? [] keys, nint count)
{
if (!ValidateFromObjectsAndKeys (objects, keys, count))
return new NSMutableDictionary ();
Expand Down
12 changes: 6 additions & 6 deletions src/Foundation/NSMutableDictionary_2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public NSMutableDictionary (NSDictionary<TKey, TValue> other)
{
}

NSMutableDictionary (TKey [] keys, TValue [] values, bool validation)
NSMutableDictionary (TKey? [] keys, TValue? [] values, bool validation)
: base (NSArray.FromNSObjects (values), NSArray.FromNSObjects (keys))
{
}
Expand All @@ -100,7 +100,7 @@ public NSMutableDictionary (TKey [] keys, TValue [] values)
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public NSMutableDictionary (TKey key, TValue value)
public NSMutableDictionary (TKey? key, TValue? value)
: base (NSArray.FromNSObjects (value), NSArray.FromNSObjects (key))
{
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public TValue [] ObjectsForKeys (TKey [] keys, TValue marker)
if (keys.Length == 0)
return [];

var keysArray = NSArray.From<TKey> (keys);
var keysArray = NSArray.FromNativeObjects<TKey> (keys);
var result = NSArray.ArrayFromHandle<TValue> (_ObjectsForKeys (keysArray.Handle, marker.Handle));
GC.KeepAlive (keysArray);
GC.KeepAlive (marker);
Expand Down Expand Up @@ -263,7 +263,7 @@ public TValue? this [TKey index] {
/// <param name="keys">An array of keys.</param>
/// <param name="count">The number of elements to use from each array.</param>
/// <returns>A new mutable dictionary containing the specified key-value pairs.</returns>
public static NSMutableDictionary<TKey, TValue>? FromObjectsAndKeys (TValue [] objects, TKey [] keys, nint count)
public static NSMutableDictionary<TKey, TValue>? FromObjectsAndKeys (TValue? [] objects, TKey? [] keys, nint count)
{
if (!ValidateFromObjectsAndKeys (objects, keys, count))
return new NSMutableDictionary<TKey, TValue> ();
Expand All @@ -279,7 +279,7 @@ public TValue? this [TKey index] {
/// <param name="objects">An array of values.</param>
/// <param name="keys">An array of keys.</param>
/// <returns>A new mutable dictionary containing the specified key-value pairs.</returns>
public static NSMutableDictionary<TKey, TValue>? FromObjectsAndKeys (TValue [] objects, TKey [] keys)
public static NSMutableDictionary<TKey, TValue>? FromObjectsAndKeys (TValue? [] objects, TKey? [] keys)
{
if (!ValidateFromObjectsAndKeys (objects, keys))
return new NSMutableDictionary<TKey, TValue> ();
Expand Down Expand Up @@ -308,7 +308,7 @@ public TValue? this [TKey index] {
/// <param name="keys">An array of <see cref="NSObject"/> keys.</param>
/// <param name="count">The number of elements to use from each array.</param>
/// <returns>A new mutable dictionary containing the specified key-value pairs.</returns>
public static NSMutableDictionary<TKey, TValue>? FromObjectsAndKeys (NSObject [] objects, NSObject [] keys, nint count)
public static NSMutableDictionary<TKey, TValue>? FromObjectsAndKeys (NSObject? [] objects, NSObject? [] keys, nint count)
{
if (!ValidateFromObjectsAndKeys (objects, keys, count))
return new NSMutableDictionary<TKey, TValue> ();
Expand Down
4 changes: 2 additions & 2 deletions src/Foundation/NSMutableSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Foundation {
public partial class NSMutableSet : IEnumerable<NSObject> {
/// <summary>Initializes a new mutable set with the specified objects.</summary>
/// <param name="objs">The objects to add to the set.</param>
public NSMutableSet (params NSObject [] objs)
public NSMutableSet (params NSObject? []? objs)
: this (NSArray.FromNSObjects (objs))
{
}
Expand All @@ -50,7 +50,7 @@ public NSMutableSet (params string [] strings)
{
}

internal NSMutableSet (params INativeObject [] objs)
internal NSMutableSet (params INativeObject? []? objs)
: this (NSArray.FromNSObjects (objs))
{
}
Expand Down
6 changes: 1 addition & 5 deletions src/Foundation/NSMutableSet_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ public void AddObjects (params TKey [] objects)
if (objects is null)
throw new ArgumentNullException (nameof (objects));

for (int i = 0; i < objects.Length; i++)
if (objects [i] is null)
throw new ArgumentNullException (nameof (objects) + "[" + i.ToString () + "]");

using (var array = NSArray.From<TKey> (objects))
using (var array = NSArray.FromNonNullNativeObjects<TKey> (objects))
_AddObjects (array.Handle);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Foundation/NSOrderedSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class NSOrderedSet : IEnumerable<NSObject> {

/// <summary>Initializes a new instance of the <see cref="NSOrderedSet" /> class from an array of <see cref="NSObject" /> instances.</summary>
/// <param name="objs">An array of <see cref="NSObject" /> instances to include in the set.</param>
public NSOrderedSet (params NSObject [] objs) : this (NSArray.FromNSObjects (objs))
public NSOrderedSet (params NSObject? []? objs) : this (NSArray.FromNSObjects (objs))
{
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public T [] ToArray<T> () where T : class, INativeObject
/// <typeparam name="T">The type of values in the array, must be a class that derives from <see cref="NSObject" />.</typeparam>
/// <param name="values">An array of strongly typed values to include in the ordered set.</param>
/// <returns>A new <see cref="NSOrderedSet" /> containing the specified values.</returns>
public static NSOrderedSet MakeNSOrderedSet<T> (T [] values) where T : NSObject
public static NSOrderedSet MakeNSOrderedSet<T> (T? []? values) where T : NSObject
{
NSArray a = NSArray.FromNSObjects (values);
var result = (NSOrderedSet) Runtime.GetNSObject (ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (class_ptr, Selector.GetHandle (selSetWithArray), a.Handle))!;
Expand Down Expand Up @@ -231,7 +231,7 @@ public bool Contains (object? obj)
public partial class NSMutableOrderedSet {
/// <summary>Initializes a new instance of the <see cref="NSMutableOrderedSet" /> class from an array of <see cref="NSObject" /> instances.</summary>
/// <param name="objs">An array of <see cref="NSObject" /> instances to include in the set.</param>
public NSMutableOrderedSet (params NSObject [] objs) : this (NSArray.FromNSObjects (objs))
public NSMutableOrderedSet (params NSObject? []? objs) : this (NSArray.FromNSObjects (objs))
{
}

Expand Down
2 changes: 0 additions & 2 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11806,8 +11806,6 @@ M:Foundation.INSUrlSessionWebSocketDelegate.DidOpen(Foundation.NSUrlSession,Foun
M:Foundation.INSXpcListenerDelegate.ShouldAcceptConnection(Foundation.NSXpcListener,Foundation.NSXpcConnection)
M:Foundation.NSArray.ArrayFromHandle``1(ObjCRuntime.NativeHandle,System.Converter{ObjCRuntime.NativeHandle,``0},System.Boolean)
M:Foundation.NSArray.EnumsFromHandle``1(ObjCRuntime.NativeHandle)
M:Foundation.NSArray.FromNSObjects``1(``0[][])
M:Foundation.NSArray.FromNSObjects``1(``0[0:,0:])
M:Foundation.NSArray.FromStrings(System.Collections.Generic.IReadOnlyList{System.String})
M:Foundation.NSArray.ToArray
M:Foundation.NSArray.ToArray``1
Expand Down
2 changes: 1 addition & 1 deletion tests/cecil-tests/HandleSafety.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public partial class HandleSafetyTest {
"Foundation.DictionaryContainer.SetNativeValue (Foundation.NSString, ObjCRuntime.INativeObject, System.Boolean)",
"Foundation.DictionaryContainer.TryGetNativeValue (ObjCRuntime.NativeHandle, ObjCRuntime.NativeHandle&)",
"Foundation.DictionaryContainerHelper.GetHandle (Foundation.DictionaryContainer)",
"Foundation.NSArray.FromNativeObjects`1 (T[], System.IntPtr)",
"Foundation.NSArray.FromNativeObjectsImpl`1 (T[], System.IntPtr, System.Boolean)",
"Foundation.NSArray.FromNSObjects (System.Collections.Generic.IList`1<Foundation.NSObject>)",
"Foundation.NSArray.FromStrings (System.Collections.Generic.IReadOnlyList`1<System.String>)",
"Foundation.NSArray.UnsafeGetItem (ObjCRuntime.NativeHandle, System.UIntPtr, System.Type)",
Expand Down
Loading
Loading