[src] Change some NSString API to take/return NativeHandle instead of IntPtr for .NET. (#13492)

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
This commit is contained in:
Rolf Bjarne Kvinge 2021-12-07 21:13:41 +01:00 коммит произвёл GitHub
Родитель 90b8e89859
Коммит 341d7aed9a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 13 добавлений и 13 удалений

Просмотреть файл

@ -67,7 +67,7 @@ namespace Foundation {
{ {
} }
static IntPtr CreateWithCharacters (IntPtr handle, string str, int offset, int length, bool autorelease = false) static NativeHandle CreateWithCharacters (NativeHandle handle, string str, int offset, int length, bool autorelease = false)
{ {
unsafe { unsafe {
fixed (char *ptrFirstChar = str) { fixed (char *ptrFirstChar = str) {
@ -87,28 +87,28 @@ namespace Foundation {
} }
[Obsolete ("Use of 'CFString.CreateNative' offers better performance.")] [Obsolete ("Use of 'CFString.CreateNative' offers better performance.")]
public static IntPtr CreateNative (string str) public static NativeHandle CreateNative (string str)
{ {
return CreateNative (str, false); return CreateNative (str, false);
} }
public static IntPtr CreateNative (string str, bool autorelease) public static NativeHandle CreateNative (string str, bool autorelease)
{ {
if (str == null) if (str is null)
return IntPtr.Zero; return NativeHandle.Zero;
return CreateNative (str, 0, str.Length, autorelease); return CreateNative (str, 0, str.Length, autorelease);
} }
public static IntPtr CreateNative (string value, int start, int length) public static NativeHandle CreateNative (string value, int start, int length)
{ {
return CreateNative (value, start, length, false); return CreateNative (value, start, length, false);
} }
public static IntPtr CreateNative (string value, int start, int length, bool autorelease) public static NativeHandle CreateNative (string value, int start, int length, bool autorelease)
{ {
if (value == null) if (value is null)
return IntPtr.Zero; return NativeHandle.Zero;
if (start < 0 || start > value.Length) if (start < 0 || start > value.Length)
throw new ArgumentOutOfRangeException (nameof (start)); throw new ArgumentOutOfRangeException (nameof (start));
@ -125,7 +125,7 @@ namespace Foundation {
return CreateWithCharacters (handle, value, start, length, autorelease); return CreateWithCharacters (handle, value, start, length, autorelease);
} }
public static void ReleaseNative (IntPtr handle) public static void ReleaseNative (NativeHandle handle)
{ {
NSObject.DangerousRelease (handle); NSObject.DangerousRelease (handle);
} }
@ -170,15 +170,15 @@ namespace Foundation {
} }
[Obsolete ("Use of 'CFString.FromHandle' offers better performance.")] [Obsolete ("Use of 'CFString.FromHandle' offers better performance.")]
public static string FromHandle (IntPtr usrhandle) public static string FromHandle (NativeHandle usrhandle)
{ {
return FromHandle (usrhandle, false); return FromHandle (usrhandle, false);
} }
[Obsolete ("Use of 'CFString.FromHandle' offers better performance.")] [Obsolete ("Use of 'CFString.FromHandle' offers better performance.")]
public static string FromHandle (IntPtr handle, bool owns) public static string FromHandle (NativeHandle handle, bool owns)
{ {
if (handle == IntPtr.Zero) if (handle == NativeHandle.Zero)
return null; return null;
try { try {