Skip to content

Commit bf4063b

Browse files
authored
[Foundation] Improve and simplify the manually bound constructors for NSString slightly. (#22659)
Improve and simplify the manually bound constructors for NSString by using the same pattern we use elsewhere for manually bound constructors.
1 parent e720c6e commit bf4063b

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/Foundation/NSString.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,23 @@ public static void ReleaseNative (NativeHandle handle)
156156
NSObject.DangerousRelease (handle);
157157
}
158158

159-
/// <param name="str">A string.</param>
160-
/// <summary>Creates an NSString from a C# string.</summary>
161-
/// <remarks>To be added.</remarks>
159+
/// <summary>Creates an <see cref="NSString" /> from a C# string.</summary>
160+
/// <param name="str">A C# string to create an <see cref="NSString" /> from.</param>
162161
public NSString (string str)
162+
: base (NSObjectFlag.Empty)
163163
{
164164
if (str is null)
165-
throw new ArgumentNullException ("str");
165+
throw new ArgumentNullException (nameof (str));
166166

167-
Handle = CreateWithCharacters (Handle, str, 0, str.Length);
167+
InitializeHandle (CreateWithCharacters (Handle, str, 0, str.Length));
168168
}
169169

170-
/// <param name="value">To be added.</param>
171-
/// <param name="start">To be added.</param>
172-
/// <param name="length">To be added.</param>
173-
/// <summary>To be added.</summary>
174-
/// <remarks>To be added.</remarks>
170+
/// <summary>Creates an <see cref="NSString" /> from a C# string.</summary>
171+
/// <param name="value">A C# string to create an <see cref="NSString" /> from.</param>
172+
/// <param name="start">The starting index of the <paramref name="value" /> string to create the <see cref="NSString" /> from.</param>
173+
/// <param name="length">The length, starting at <paramref name="start" />, of the <paramref name="value" /> string to create the <see cref="NSString" /> from.</param>
175174
public NSString (string value, int start, int length)
175+
: base (NSObjectFlag.Empty)
176176
{
177177
if (value is null)
178178
throw new ArgumentNullException (nameof (value));
@@ -183,7 +183,7 @@ public NSString (string value, int start, int length)
183183
if (length < 0 || start > value.Length - length)
184184
throw new ArgumentOutOfRangeException (nameof (length));
185185

186-
Handle = CreateWithCharacters (Handle, value, start, length);
186+
InitializeHandle (CreateWithCharacters (Handle, value, start, length));
187187
}
188188

189189
/// <summary>Returns a string representation of the value of the current instance.</summary>

tests/cecil-tests/ConstructorTest.KnownFailures.cs

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public partial class ConstructorTest {
2424
"Foundation.NSMutableArray`1::.ctor(TValue[])",
2525
"Foundation.NSObject::.ctor(Foundation.NSObjectFlag)",
2626
"Foundation.NSObject::.ctor(ObjCRuntime.NativeHandle,System.Boolean)",
27-
"Foundation.NSString::.ctor(System.String,System.Int32,System.Int32)",
28-
"Foundation.NSString::.ctor(System.String)",
2927
"Foundation.NSSynchronizationContextDispatcher::.ctor(System.Threading.SendOrPostCallback,System.Object)",
3028
"Foundation.NSThread::.ctor(Foundation.NSObject,ObjCRuntime.Selector,Foundation.NSObject)",
3129
"Foundation.NSTimerActionDispatcher::.ctor(System.Action`1<Foundation.NSTimer>)",

tests/cecil-tests/SetHandleTest.KnownFailures.cs

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +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.NSString::.ctor(System.String,System.Int32,System.Int32)",
22-
"Foundation.NSString::.ctor(System.String)",
2321
"Foundation.NSThread::.ctor(Foundation.NSObject,ObjCRuntime.Selector,Foundation.NSObject)",
2422
"Foundation.NSUuid::.ctor(System.Byte[])",
2523
"GameplayKit.GKPath::.ctor(System.Numerics.Vector2[],System.Single,System.Boolean)",

0 commit comments

Comments
 (0)