mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2025-01-09 22:52:00 +00:00
misc: Use selector fields
This commit is contained in:
parent
664c63c6a8
commit
7d54424048
1 changed files with 6 additions and 2 deletions
|
@ -1,19 +1,23 @@
|
||||||
using SharpMetal.Foundation;
|
using SharpMetal.Foundation;
|
||||||
using SharpMetal.ObjectiveCCore;
|
using SharpMetal.ObjectiveCCore;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal.SharpMetalExtensions
|
namespace Ryujinx.Graphics.Metal.SharpMetalExtensions
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macOS")]
|
[SupportedOSPlatform("macOS")]
|
||||||
public static class NSHelper
|
public static class NSHelper
|
||||||
{
|
{
|
||||||
|
private static readonly Selector sel_getCStringMaxLengthEncoding = "getCString:maxLength:encoding:";
|
||||||
|
private static readonly Selector sel_stringWithUTF8String = "stringWithUTF8String:";
|
||||||
|
|
||||||
public static unsafe string ToDotNetString(this NSString source)
|
public static unsafe string ToDotNetString(this NSString source)
|
||||||
{
|
{
|
||||||
char[] sourceBuffer = new char[source.Length];
|
char[] sourceBuffer = new char[source.Length];
|
||||||
fixed (char* pSourceBuffer = sourceBuffer)
|
fixed (char* pSourceBuffer = sourceBuffer)
|
||||||
{
|
{
|
||||||
ObjectiveC.bool_objc_msgSend(source,
|
ObjectiveC.bool_objc_msgSend(source,
|
||||||
"getCString:maxLength:encoding:",
|
sel_getCStringMaxLengthEncoding,
|
||||||
pSourceBuffer,
|
pSourceBuffer,
|
||||||
source.MaximumLengthOfBytes(NSStringEncoding.UTF16) + 1,
|
source.MaximumLengthOfBytes(NSStringEncoding.UTF16) + 1,
|
||||||
(ulong)NSStringEncoding.UTF16);
|
(ulong)NSStringEncoding.UTF16);
|
||||||
|
@ -23,6 +27,6 @@ namespace Ryujinx.Graphics.Metal.SharpMetalExtensions
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NSString ToNSString(this string source)
|
public static NSString ToNSString(this string source)
|
||||||
=> new(ObjectiveC.IntPtr_objc_msgSend(new ObjectiveCClass("NSString"), "stringWithUTF8String:", source));
|
=> new(ObjectiveC.IntPtr_objc_msgSend(new ObjectiveCClass(nameof(NSString)), sel_stringWithUTF8String, source));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue