using System; namespace UnityEditor.XR.ARKit { static class GuidExtensions { /// /// Assumes the guid is an NSUUID and returns a string in the same format as /// [NSUUID.UUIDString](https://developer.apple.com/documentation/foundation/nsuuid/1416585-uuidstring). /// /// The guid to convert to a string /// A string representation of the GUID in "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" format. public static string ToUUIDString(this Guid guid) { // When converting to a string representation, // C# reverses the byte order of the last 2 integral components // while Core Foundation's NSUUID.UUIDString reverses all 5. // We want to generate a string that will match what NSUUID.UUIDString // will produce, so we need to reverse the first 3 components. var bytes = guid.ToByteArray(); Array.Reverse(bytes, 0, 4); Array.Reverse(bytes, 4, 2); Array.Reverse(bytes, 6, 2); return new Guid(bytes).ToString("D").ToUpper(); } } }