Skip to content

Commit 5ebebd5

Browse files
authored
[AppKit] Improve and simplify the manually bound constructors for NSOpenGLPixelFormat slightly. (#22716)
Improve and simplify the manually bound constructors for NSOpenGLPixelFormat by using the same pattern we use elsewhere for manually bound constructors.
1 parent 41d2f6d commit 5ebebd5

File tree

2 files changed

+18
-43
lines changed

2 files changed

+18
-43
lines changed

src/AppKit/NSOpenGLPixelFormat.cs

+18-41
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,46 @@ namespace AppKit {
3838
public partial class NSOpenGLPixelFormat {
3939
static IntPtr selInitWithAttributes = Selector.GetHandle ("initWithAttributes:");
4040

41-
/// <param name="attribs">To be added.</param>
42-
/// <summary>To be added.</summary>
43-
/// <remarks>To be added.</remarks>
44-
public NSOpenGLPixelFormat (NSOpenGLPixelFormatAttribute [] attribs) : base (NSObjectFlag.Empty)
41+
/// <summary>Create a new <see cref="NSOpenGLPixelFormat" /> instance with the specified attributes.</summary>
42+
/// <param name="attribs">The attributes to initialize the new <see cref="NSOpenGLPixelFormat" /> instance with.</param>
43+
public NSOpenGLPixelFormat (NSOpenGLPixelFormatAttribute [] attribs)
44+
: base (NSObjectFlag.Empty)
4545
{
4646
if (attribs is null)
47-
throw new ArgumentNullException ("attribs");
47+
throw new ArgumentNullException (nameof (attribs));
4848

4949
unsafe {
5050
NSOpenGLPixelFormatAttribute [] copy = new NSOpenGLPixelFormatAttribute [attribs.Length + 1];
5151
Array.Copy (attribs, 0, copy, 0, attribs.Length);
5252

5353
fixed (NSOpenGLPixelFormatAttribute* pArray = copy) {
5454
if (IsDirectBinding) {
55-
Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, selInitWithAttributes, new IntPtr ((void*) pArray));
55+
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, selInitWithAttributes, new IntPtr ((void*) pArray)), "initWithAttributes:");
5656
} else {
57-
Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, selInitWithAttributes, new IntPtr ((void*) pArray));
57+
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, selInitWithAttributes, new IntPtr ((void*) pArray)), "initWithAttributes:");
5858
}
5959
}
6060

6161
}
6262
}
6363

64-
/// <param name="attribs">To be added.</param>
65-
/// <summary>To be added.</summary>
66-
/// <remarks>To be added.</remarks>
67-
public NSOpenGLPixelFormat (uint [] attribs) : base (NSObjectFlag.Empty)
64+
/// <summary>Create a new <see cref="NSOpenGLPixelFormat" /> instance with the specified attributes.</summary>
65+
/// <param name="attribs">The attributes to initialize the new <see cref="NSOpenGLPixelFormat" /> instance with.</param>
66+
public NSOpenGLPixelFormat (uint [] attribs)
67+
: base (NSObjectFlag.Empty)
6868
{
6969
if (attribs is null)
70-
throw new ArgumentNullException ("attribs");
70+
throw new ArgumentNullException (nameof (attribs));
7171

7272
unsafe {
7373
uint [] copy = new uint [attribs.Length + 1];
7474
Array.Copy (attribs, 0, copy, 0, attribs.Length);
7575

7676
fixed (uint* pArray = copy) {
7777
if (IsDirectBinding) {
78-
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, selInitWithAttributes, new IntPtr ((void*) pArray)));
78+
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, selInitWithAttributes, new IntPtr ((void*) pArray)), "initWithAttributes:");
7979
} else {
80-
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, selInitWithAttributes, new IntPtr ((void*) pArray)));
80+
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, selInitWithAttributes, new IntPtr ((void*) pArray)), "initWithAttributes:");
8181
}
8282
}
8383

@@ -156,34 +156,11 @@ static uint [] ConvertToAttributes (object [] args)
156156
return list.ToArray ();
157157
}
158158

159-
/// <param name="attribs">To be added.</param>
160-
/// <summary>To be added.</summary>
161-
/// <remarks>To be added.</remarks>
162-
public NSOpenGLPixelFormat (params object [] attribs) : this (ConvertToAttributes (attribs))
159+
/// <summary>Create a new <see cref="NSOpenGLPixelFormat" /> instance with the specified attributes.</summary>
160+
/// <param name="attribs">The attributes to initialize the new <see cref="NSOpenGLPixelFormat" /> instance with.</param>
161+
public NSOpenGLPixelFormat (params object [] attribs)
162+
: this (ConvertToAttributes (attribs))
163163
{
164-
if (attribs is null)
165-
throw new ArgumentNullException ("attribs");
166-
167-
unsafe {
168-
var copy = new NSOpenGLPixelFormatAttribute [attribs.Length + 1 /* null termination */];
169-
for (int i = 0; i < attribs.Length; i++) {
170-
var input = attribs [i];
171-
if (input is NSOpenGLPixelFormatAttribute) {
172-
copy [i] = (NSOpenGLPixelFormatAttribute) input;
173-
} else {
174-
copy [i] = (NSOpenGLPixelFormatAttribute) (int) input;
175-
}
176-
}
177-
178-
fixed (NSOpenGLPixelFormatAttribute* pArray = copy) {
179-
if (IsDirectBinding) {
180-
Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, selInitWithAttributes, new IntPtr ((void*) pArray));
181-
} else {
182-
Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, selInitWithAttributes, new IntPtr ((void*) pArray));
183-
}
184-
}
185-
186-
}
187164
}
188165
}
189166
}

tests/cecil-tests/SetHandleTest.KnownFailures.cs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ namespace Cecil.Tests {
66
public partial class SetHandleTest {
77
static HashSet<string> knownFailuresNobodyCallsHandleSetter = new HashSet<string> {
88
"AddressBook.ABGroup::.ctor(AddressBook.ABRecord)",
9-
"AppKit.NSOpenGLPixelFormat::.ctor(AppKit.NSOpenGLPixelFormatAttribute[])",
10-
"AppKit.NSOpenGLPixelFormat::.ctor(System.Object[])",
119
"CoreFoundation.CFMutableString::.ctor(CoreFoundation.CFString,System.IntPtr)",
1210
"CoreFoundation.CFMutableString::.ctor(System.String,System.IntPtr)",
1311
"CoreFoundation.CFSocket::Initialize(CoreFoundation.CFRunLoop,CoreFoundation.CFSocket/CreateSocket)",

0 commit comments

Comments
 (0)