/// <summary> /// Gets the string representation of the given object ID. It matches the internal serialization formatting rules. /// </summary> /// <param name="id">The object identifier.</param> /// <returns>The serialized ID.</returns> public static unsafe string GetStringID(Guid id) { // TODO: make to more efficent, don't use string format, use cached string buffer, dont allocate any byte during this conversion GuidInterop *g = (GuidInterop *)&id; return(string.Format("{0:x8}{1:x8}{2:x8}{3:x8}", g->A, g->B, g->C, g->D)); }
/// <summary> /// Gets the string representation of the given object ID. It matches the internal serialization formatting rules. /// </summary> /// <param name="id">The object identifier.</param> /// <returns>The serialized ID.</returns> public static unsafe string GetStringID(Guid *id) { GuidInterop *g = (GuidInterop *)id; // Unoptimized version: //return string.Format("{0:x8}{1:x8}{2:x8}{3:x8}", g->A, g->B, g->C, g->D); // Optimized version: var buffer = (char *)CachedGuidBuffer.Value.ToPointer(); for (int i = 0; i < 32; i++) { buffer[i] = '0'; } var digits = CachedGuidDigits; uint n = g->A; char *p = buffer + 7; do { *p-- = digits[(int)(n & 0xf)]; } while ((n >>= 4) != 0); n = g->B; p = buffer + 15; do { *p-- = digits[(int)(n & 0xf)]; } while ((n >>= 4) != 0); n = g->C; p = buffer + 23; do { *p-- = digits[(int)(n & 0xf)]; } while ((n >>= 4) != 0); n = g->D; p = buffer + 31; do { *p-- = digits[(int)(n & 0xf)]; } while ((n >>= 4) != 0); return(new string(buffer, 0, 32)); }
internal static unsafe string GetStringID(Guid id) { GuidInterop *g = (GuidInterop *)&id; return(string.Format("{0:x8}{1:x8}{2:x8}{3:x8}", g->A, g->B, g->C, g->D)); }