Skip to content

Commit 93a1a29

Browse files
authored
[Foundation] Improve and simplify the manually bound constructors for NSThread slightly. (#22662)
Improve and simplify the manually bound constructors for NSThread by using the same pattern we use elsewhere for manually bound constructors.
1 parent e6d7a78 commit 93a1a29

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/Foundation/NSThread.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,45 @@
2626

2727
using ObjCRuntime;
2828

29+
#nullable enable
30+
2931
namespace Foundation {
3032

3133
public partial class NSThread {
32-
33-
/// <summary>To be added.</summary>
34-
/// <value>To be added.</value>
35-
/// <remarks>To be added.</remarks>
34+
/// <summary>Get or set the current thread's priority.</summary>
35+
/// <value>The current thread's priority, between 0.0 (lowest priority) and 1.0 (highest priority).</value>
3636
public static double Priority {
3737
get { return _GetPriority (); }
3838
// ignore the boolean return value
3939
set { _SetPriority (value); }
4040
}
4141

4242
[DllImport ("__Internal")]
43-
static extern IntPtr xamarin_init_nsthread (IntPtr handle, byte is_direct_binding, IntPtr target, IntPtr selector, IntPtr argument);
43+
static extern NativeHandle xamarin_init_nsthread (IntPtr handle, byte is_direct_binding, IntPtr target, IntPtr selector, IntPtr argument);
4444

45-
IntPtr InitNSThread (NSObject target, Selector selector, NSObject argument)
45+
NativeHandle InitNSThread (NSObject target, Selector selector, NSObject? argument)
4646
{
4747
if (target is null)
48-
throw new ArgumentNullException ("target");
48+
ThrowHelper.ThrowArgumentNullException (nameof (target));
4949
if (selector is null)
50-
throw new ArgumentNullException ("selector");
50+
ThrowHelper.ThrowArgumentNullException (nameof (selector));
5151

52-
IntPtr result = xamarin_init_nsthread (IsDirectBinding ? this.Handle : this.SuperHandle, IsDirectBinding.AsByte (), target.Handle, selector.Handle, argument is null ? IntPtr.Zero : argument.Handle);
52+
IntPtr result = xamarin_init_nsthread (IsDirectBinding ? this.Handle : this.SuperHandle, IsDirectBinding.AsByte (), target.Handle, selector.Handle, argument.GetHandle ());
5353
GC.KeepAlive (target);
5454
GC.KeepAlive (selector);
5555
GC.KeepAlive (argument);
5656
return result;
5757
}
5858

59+
/// <summary>Create a new thread.</summary>
60+
/// <param name="target">The object with the method to execute on the new thread.</param>
61+
/// <param name="selector">The selector that specifies the method to execute on the new thread.</param>
62+
/// <param name="argument">The argument to pass to the method to execute on the new thread.</param>
5963
[Export ("initWithTarget:selector:object:")]
60-
public NSThread (NSObject target, Selector selector, NSObject argument)
61-
: base ()
64+
public NSThread (NSObject target, Selector selector, NSObject? argument)
65+
: base (NSObjectFlag.Empty)
6266
{
63-
Handle = InitNSThread (target, selector, argument);
67+
InitializeHandle (InitNSThread (target, selector, argument), "initWithTarget:selector:object:");
6468
}
6569
}
6670
}

tests/cecil-tests/ConstructorTest.KnownFailures.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public partial class ConstructorTest {
2222
"Foundation.NSObject::.ctor(Foundation.NSObjectFlag)",
2323
"Foundation.NSObject::.ctor(ObjCRuntime.NativeHandle,System.Boolean)",
2424
"Foundation.NSSynchronizationContextDispatcher::.ctor(System.Threading.SendOrPostCallback,System.Object)",
25-
"Foundation.NSThread::.ctor(Foundation.NSObject,ObjCRuntime.Selector,Foundation.NSObject)",
2625
"Foundation.NSTimerActionDispatcher::.ctor(System.Action`1<Foundation.NSTimer>)",
2726
"GameplayKit.GKPath::.ctor(System.Numerics.Vector2[],System.Single,System.Boolean)",
2827
"GameplayKit.GKPath::.ctor(System.Numerics.Vector3[],System.Single,System.Boolean)",

tests/cecil-tests/SetHandleTest.KnownFailures.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public partial class SetHandleTest {
1818
"CoreGraphics.CGPattern::.ctor(CoreGraphics.CGRect,CoreGraphics.CGAffineTransform,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat,CoreGraphics.CGPatternTiling,System.Boolean,CoreGraphics.CGPattern/DrawPattern)",
1919
"Foundation.NSHttpCookie::CreateCookie(System.String,System.String,System.String,System.String,System.String,System.String,System.Nullable`1<System.Boolean>,System.Nullable`1<System.DateTime>,System.Nullable`1<System.Int32>,System.String,System.Nullable`1<System.Boolean>,System.Nullable`1<System.Int32>)",
2020
"Foundation.NSKeyedUnarchiver::.ctor(Foundation.NSData)",
21-
"Foundation.NSThread::.ctor(Foundation.NSObject,ObjCRuntime.Selector,Foundation.NSObject)",
2221
"Foundation.NSUuid::.ctor(System.Byte[])",
2322
"GameplayKit.GKPath::.ctor(System.Numerics.Vector2[],System.Single,System.Boolean)",
2423
"GameplayKit.GKPath::.ctor(System.Numerics.Vector3[],System.Single,System.Boolean)",

tests/xtro-sharpie/api-annotations-dotnet/common-Foundation.ignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,6 @@
12961296
!missing-null-allowed! 'System.Void Foundation.NSSortDescriptor::.ctor(System.String,System.Boolean)' is missing an [NullAllowed] on parameter #0
12971297
!missing-null-allowed! 'System.Void Foundation.NSSortDescriptor::.ctor(System.String,System.Boolean,Foundation.NSComparator)' is missing an [NullAllowed] on parameter #0
12981298
!missing-null-allowed! 'System.Void Foundation.NSSortDescriptor::.ctor(System.String,System.Boolean,ObjCRuntime.Selector)' is missing an [NullAllowed] on parameter #0
1299-
!missing-null-allowed! 'System.Void Foundation.NSThread::.ctor(Foundation.NSObject,ObjCRuntime.Selector,Foundation.NSObject)' is missing an [NullAllowed] on parameter #2
13001299
!missing-null-allowed! 'System.Void Foundation.NSTimeZone::.ctor(System.String,Foundation.NSData)' is missing an [NullAllowed] on parameter #1
13011300
!missing-null-allowed! 'System.Void Foundation.NSUrl::.ctor(System.String,Foundation.NSUrl)' is missing an [NullAllowed] on parameter #1
13021301
!missing-null-allowed! 'System.Void Foundation.NSUrl::SetTemporaryResourceValue(Foundation.NSObject,Foundation.NSString)' is missing an [NullAllowed] on parameter #0

0 commit comments

Comments
 (0)