13[TypeForwardedFrom(
"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
14public readonly
struct Guid :
ISpanFormattable,
IFormattable,
IComparable,
IComparable<Guid>,
IEquatable<Guid>,
IComparisonOperators<Guid, Guid>,
IEqualityOperators<Guid, Guid>,
ISpanParseable<Guid>,
IParseable<Guid>
62 internal readonly
void SetFailure(
bool overflow,
string failureMessageID)
88 private readonly
int _a;
90 private readonly
short _b;
92 private readonly
short _c;
94 private readonly
byte _d;
96 private readonly
byte _e;
98 private readonly
byte _f;
100 private readonly
byte _g;
102 private readonly
byte _h;
104 private readonly
byte _i;
106 private readonly
byte _j;
108 private readonly
byte _k;
125 [CLSCompliant(
false)]
126 public Guid(uint a, ushort b, ushort c,
byte d,
byte e,
byte f,
byte g,
byte h,
byte i,
byte j,
byte k)
141 public Guid(
int a,
short b,
short c,
byte[] d)
164 public Guid(
int a,
short b,
short c,
byte d,
byte e,
byte f,
byte g,
byte h,
byte i,
byte j,
byte k)
210 result =
default(
Guid);
221 result = result2.
ToGuid();
224 result =
default(
Guid);
250 bool flag = (char)(ushort)(
format[0] | 0x20)
switch
266 result =
default(
Guid);
276 result =
default(
Guid);
282 switch ((
char)(ushort)(
format[0] | 0x20))
302 result = result2.
ToGuid();
305 result =
default(
Guid);
311 guidString = guidString.Trim();
312 if (guidString.
Length == 0)
314 result.SetFailure(overflow:
false,
"Format_GuidUnrecognized");
317 return guidString[0]
switch
327 if (guidString.
Length != 38 || guidString[0] !=
'{' || guidString[37] !=
'}')
329 result.SetFailure(overflow:
false,
"Format_GuidInvLen");
337 if (guidString.
Length != 36 || guidString[8] !=
'-' || guidString[13] !=
'-' || guidString[18] !=
'-' || guidString[23] !=
'-')
339 result.SetFailure(overflow:
false, (guidString.Length != 36) ?
"Format_GuidInvLen" :
"Format_GuidDashes");
343 int invalidIfNegative = 0;
344 span[0] =
DecodeByte(guidString[6], guidString[7], ref invalidIfNegative);
345 span[1] =
DecodeByte(guidString[4], guidString[5], ref invalidIfNegative);
346 span[2] =
DecodeByte(guidString[2], guidString[3], ref invalidIfNegative);
347 span[3] =
DecodeByte(guidString[0], guidString[1], ref invalidIfNegative);
348 span[4] =
DecodeByte(guidString[11], guidString[12], ref invalidIfNegative);
349 span[5] =
DecodeByte(guidString[9], guidString[10], ref invalidIfNegative);
350 span[6] =
DecodeByte(guidString[16], guidString[17], ref invalidIfNegative);
351 span[7] =
DecodeByte(guidString[14], guidString[15], ref invalidIfNegative);
352 span[8] =
DecodeByte(guidString[19], guidString[20], ref invalidIfNegative);
353 span[9] =
DecodeByte(guidString[21], guidString[22], ref invalidIfNegative);
354 span[10] =
DecodeByte(guidString[24], guidString[25], ref invalidIfNegative);
355 span[11] =
DecodeByte(guidString[26], guidString[27], ref invalidIfNegative);
356 span[12] =
DecodeByte(guidString[28], guidString[29], ref invalidIfNegative);
357 span[13] =
DecodeByte(guidString[30], guidString[31], ref invalidIfNegative);
358 span[14] =
DecodeByte(guidString[32], guidString[33], ref invalidIfNegative);
359 span[15] =
DecodeByte(guidString[34], guidString[35], ref invalidIfNegative);
360 if (invalidIfNegative >= 0)
367 if (guidString.IndexOfAny(
'X',
'x',
'+') != -1 && TryCompatParsing(guidString, ref result))
371 result.SetFailure(overflow:
false,
"Format_GuidInvalidChar");
377 result._b = (ushort)result2;
380 result._c = (ushort)result2;
411 if (guidString.
Length != 32)
413 result.SetFailure(overflow:
false,
"Format_GuidInvLen");
417 int invalidIfNegative = 0;
418 span[0] =
DecodeByte(guidString[6], guidString[7], ref invalidIfNegative);
419 span[1] =
DecodeByte(guidString[4], guidString[5], ref invalidIfNegative);
420 span[2] =
DecodeByte(guidString[2], guidString[3], ref invalidIfNegative);
421 span[3] =
DecodeByte(guidString[0], guidString[1], ref invalidIfNegative);
422 span[4] =
DecodeByte(guidString[10], guidString[11], ref invalidIfNegative);
423 span[5] =
DecodeByte(guidString[8], guidString[9], ref invalidIfNegative);
424 span[6] =
DecodeByte(guidString[14], guidString[15], ref invalidIfNegative);
425 span[7] =
DecodeByte(guidString[12], guidString[13], ref invalidIfNegative);
426 span[8] =
DecodeByte(guidString[16], guidString[17], ref invalidIfNegative);
427 span[9] =
DecodeByte(guidString[18], guidString[19], ref invalidIfNegative);
428 span[10] =
DecodeByte(guidString[20], guidString[21], ref invalidIfNegative);
429 span[11] =
DecodeByte(guidString[22], guidString[23], ref invalidIfNegative);
430 span[12] =
DecodeByte(guidString[24], guidString[25], ref invalidIfNegative);
431 span[13] =
DecodeByte(guidString[26], guidString[27], ref invalidIfNegative);
432 span[14] =
DecodeByte(guidString[28], guidString[29], ref invalidIfNegative);
433 span[15] =
DecodeByte(guidString[30], guidString[31], ref invalidIfNegative);
434 if (invalidIfNegative >= 0)
441 result.SetFailure(overflow:
false,
"Format_GuidInvalidChar");
447 if (guidString.
Length != 38 || guidString[0] !=
'(' || guidString[37] !=
')')
449 result.SetFailure(overflow:
false,
"Format_GuidInvLen");
458 if (guidString.
Length == 0 || guidString[0] !=
'{')
460 result.SetFailure(overflow:
false,
"Format_GuidBrace");
465 result.SetFailure(overflow:
false,
"Format_GuidHexPrefix");
469 int num2 = guidString.
Slice(num).IndexOf(
',');
472 result.SetFailure(overflow:
false,
"Format_GuidComma");
475 bool overflow =
false;
476 if (!
TryParseHex(guidString.
Slice(num, num2), out result._a, ref overflow) || overflow)
478 result.SetFailure(overflow, overflow ?
"Overflow_UInt32" :
"Format_GuidInvalidChar");
483 result.SetFailure(overflow:
false,
"Format_GuidHexPrefix");
486 num = num + num2 + 3;
487 num2 = guidString.
Slice(num).IndexOf(
',');
490 result.SetFailure(overflow:
false,
"Format_GuidComma");
493 if (!
TryParseHex(guidString.
Slice(num, num2), out result._b, ref overflow) || overflow)
495 result.SetFailure(overflow, overflow ?
"Overflow_UInt32" :
"Format_GuidInvalidChar");
500 result.SetFailure(overflow:
false,
"Format_GuidHexPrefix");
503 num = num + num2 + 3;
504 num2 = guidString.
Slice(num).IndexOf(
',');
507 result.SetFailure(overflow:
false,
"Format_GuidComma");
510 if (!
TryParseHex(guidString.
Slice(num, num2), out result._c, ref overflow) || overflow)
512 result.SetFailure(overflow, overflow ?
"Overflow_UInt32" :
"Format_GuidInvalidChar");
515 if ((uint)guidString.Length <= (uint)(num + num2 + 1) || guidString[num + num2 + 1] !=
'{')
517 result.SetFailure(overflow:
false,
"Format_GuidBrace");
521 for (
int i = 0; i < 8; i++)
525 result.SetFailure(overflow:
false,
"Format_GuidHexPrefix");
528 num = num + num2 + 3;
531 num2 = guidString.
Slice(num).IndexOf(
',');
534 result.SetFailure(overflow:
false,
"Format_GuidComma");
540 num2 = guidString.
Slice(num).IndexOf(
'}');
543 result.SetFailure(overflow:
false,
"Format_GuidBraceAfterLastNumber");
547 if (!
TryParseHex(guidString.
Slice(num, num2), out uint result2, ref overflow) || overflow || result2 > 255)
549 result.SetFailure(overflow, overflow ?
"Overflow_UInt32" : ((result2 > 255) ?
"Overflow_Byte" :
"Format_GuidInvalidChar"));
552 Unsafe.Add(ref result._d, i) = (byte)result2;
554 if (num + num2 + 1 >= guidString.
Length || guidString[num + num2 + 1] !=
'}')
556 result.SetFailure(overflow:
false,
"Format_GuidEndBrace");
559 if (num + num2 + 1 != guidString.
Length - 1)
561 result.SetFailure(overflow:
false,
"Format_ExtraJunkAtEnd");
568 private static byte DecodeByte(nuint ch1, nuint ch2, ref
int invalidIfNegative)
572 if (ch1 < (nuint)charToHexLookup.
Length)
578 if (ch2 < (nuint)charToHexLookup.
Length)
582 int num3 = num | num2;
583 invalidIfNegative |= num3;
590 bool result3 =
TryParseHex(guidString, out result2, ref overflow);
591 result = (ushort)result2;
597 bool overflow =
false;
598 return TryParseHex(guidString, out result, ref overflow);
603 if (guidString.
Length != 0)
605 if (guidString[0] ==
'+')
607 guidString = guidString.
Slice(1);
609 if ((uint)guidString.
Length > 1u && guidString[0] ==
'0' && (guidString[1] | 0x20) == 120)
611 guidString = guidString.
Slice(2);
615 for (i = 0; i < guidString.Length && guidString[i] ==
'0'; i++)
620 for (; i < guidString.
Length; i++)
622 char c = guidString[i];
633 num2 = num2 * 16 + (uint)num3;
647 for (i = 0; i < str.Length && !
char.IsWhiteSpace(
str[i]); i++)
654 char[]
array =
new char[
str.Length];
661 for (; i <
str.Length; i++)
664 if (!
char.IsWhiteSpace(c))
674 if (i + 1 <
str.Length &&
str[i] ==
'0')
676 return (
str[i + 1] | 0x20) == 120;
683 byte[]
array =
new byte[16];
702 ref
int reference = ref
Unsafe.AsRef(in
_a);
703 return reference ^
Unsafe.Add(ref reference, 1) ^
Unsafe.Add(ref reference, 2) ^
Unsafe.Add(ref reference, 3);
706 public override bool Equals([NotNullWhen(
true)]
object? o)
722 ref
int reference = ref
Unsafe.AsRef(in left._a);
723 ref
int reference2 = ref
Unsafe.AsRef(in right._a);
724 if (reference == reference2 &&
Unsafe.Add(ref reference, 1) ==
Unsafe.Add(ref reference2, 1) &&
Unsafe.Add(ref reference, 2) ==
Unsafe.Add(ref reference2, 2))
726 return Unsafe.Add(ref reference, 3) ==
Unsafe.Add(ref reference2, 3);
861 private unsafe
static int HexsToChars(
char* guidChars,
int a,
int b)
886 if (
string.IsNullOrEmpty(
format))
918 string text =
string.FastAllocateString(
length);
979 *(ptr2++) = (
char)num;
1035 *(ptr2++) = (
char)(num >> 16);
1038 charsWritten = num2;
1047 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1050 if (left.
_a != right._a)
1052 return (uint)left._a < (uint)right._a;
1054 if (left.
_b != right._b)
1056 return (uint)left._b < (uint)right._b;
1058 if (left.
_c != right._c)
1060 return (uint)left._c < (uint)right._c;
1062 if (left.
_d != right._d)
1064 return left._d < right._d;
1066 if (left.
_e != right._e)
1068 return left._e < right._e;
1070 if (left.
_f != right._f)
1072 return left._f < right._f;
1074 if (left.
_g != right._g)
1076 return left._g < right._g;
1078 if (left.
_h != right._h)
1080 return left._h < right._h;
1082 if (left.
_i != right._i)
1084 return left._i < right._i;
1086 if (left.
_j != right._j)
1088 return left._j < right._j;
1090 if (left.
_k != right._k)
1092 return left._k < right._k;
1097 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1100 if (left.
_a != right._a)
1102 return (uint)left._a < (uint)right._a;
1104 if (left.
_b != right._b)
1106 return (uint)left._b < (uint)right._b;
1108 if (left.
_c != right._c)
1110 return (uint)left._c < (uint)right._c;
1112 if (left.
_d != right._d)
1114 return left._d < right._d;
1116 if (left.
_e != right._e)
1118 return left._e < right._e;
1120 if (left.
_f != right._f)
1122 return left._f < right._f;
1124 if (left.
_g != right._g)
1126 return left._g < right._g;
1128 if (left.
_h != right._h)
1130 return left._h < right._h;
1132 if (left.
_i != right._i)
1134 return left._i < right._i;
1136 if (left.
_j != right._j)
1138 return left._j < right._j;
1140 if (left.
_k != right._k)
1142 return left._k < right._k;
1147 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1150 if (left.
_a != right._a)
1152 return (uint)left._a > (uint)right._a;
1154 if (left.
_b != right._b)
1156 return (uint)left._b > (uint)right._b;
1158 if (left.
_c != right._c)
1160 return (uint)left._c > (uint)right._c;
1162 if (left.
_d != right._d)
1164 return left._d > right._d;
1166 if (left.
_e != right._e)
1168 return left._e > right._e;
1170 if (left.
_f != right._f)
1172 return left._f > right._f;
1174 if (left.
_g != right._g)
1176 return left._g > right._g;
1178 if (left.
_h != right._h)
1180 return left._h > right._h;
1182 if (left.
_i != right._i)
1184 return left._i > right._i;
1186 if (left.
_j != right._j)
1188 return left._j > right._j;
1190 if (left.
_k != right._k)
1192 return left._k > right._k;
1197 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1200 if (left.
_a != right._a)
1202 return (uint)left._a > (uint)right._a;
1204 if (left.
_b != right._b)
1206 return (uint)left._b > (uint)right._b;
1208 if (left.
_c != right._c)
1210 return (uint)left._c > (uint)right._c;
1212 if (left.
_d != right._d)
1214 return left._d > right._d;
1216 if (left.
_e != right._e)
1218 return left._e > right._e;
1220 if (left.
_f != right._f)
1222 return left._f > right._f;
1224 if (left.
_g != right._g)
1226 return left._g > right._g;
1228 if (left.
_h != right._h)
1230 return left._h > right._h;
1232 if (left.
_i != right._i)
1234 return left._i > right._i;
1236 if (left.
_j != right._j)
1238 return left._j > right._j;
1240 if (left.
_k != right._k)
1242 return left._k > right._k;
1247 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1250 return left == right;
1253 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1256 return left != right;
1259 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1265 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1271 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
1277 [RequiresPreviewFeatures(
"Generic Math is in preview.", Url =
"https://aka.ms/dotnet-warnings/generic-math-preview")]
static int CoCreateGuid(out Guid guid)
static readonly bool IsLittleEndian
static sbyte ReverseEndianness(sbyte value)
static char ToCharLower(int value)
static ReadOnlySpan< byte > CharToHexLookup
static int FromChar(int c)
static ParsingStatus TryParseUInt32HexNumberStyle(ReadOnlySpan< char > value, NumberStyles styles, out uint result)
static string Arg_GuidArrayCtor
static string Format(string resourceFormat, object p1)
static string Format_InvalidGuidFormatSpecification
static string GetResourceString(string resourceKey)
static string Arg_MustBeGuid
static string Format_GuidUnrecognized
static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TSelf result)
static TSelf Parse(string s, IFormatProvider? provider)
static bool TryParse(ReadOnlySpan< char > s, IFormatProvider? provider, out TSelf result)
static TSelf Parse(ReadOnlySpan< char > s, IFormatProvider? provider)
readonly void SetFailure(bool overflow, string failureMessageID)
GuidResult(GuidParseThrowStyle canThrow)
readonly GuidParseThrowStyle _throwStyle
static Guid Parse(ReadOnlySpan< char > input)
static bool EqualsCore(in Guid left, in Guid right)
string ToString(string? format, IFormatProvider? provider)
static Guid ParseExact(string input, string format)
static unsafe int HexsToChars(char *guidChars, int a, int b)
static bool TryParseExactX(ReadOnlySpan< char > guidString, ref GuidResult result)
Guid(uint a, ushort b, ushort c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)
unsafe bool TryFormat(Span< char > destination, out int charsWritten, ReadOnlySpan< char > format=default(ReadOnlySpan< char >))
static bool TryParseExact(ReadOnlySpan< char > input, ReadOnlySpan< char > format, out Guid result)
override bool Equals([NotNullWhen(true)] object? o)
string ToString(string? format)
Guid(int a, short b, short c, byte[] d)
static byte DecodeByte(nuint ch1, nuint ch2, ref int invalidIfNegative)
static bool TryParseExact([NotNullWhen(true)] string? input, [NotNullWhen(true)] string? format, out Guid result)
static bool operator!=(Guid a, Guid b)
override int GetHashCode()
static ReadOnlySpan< char > EatAllWhitespace(ReadOnlySpan< char > str)
static bool TryParseHex(ReadOnlySpan< char > guidString, out uint result, ref bool overflow)
static bool TryParse([NotNullWhen(true)] string? input, out Guid result)
static int GetResult(uint me, uint them)
static bool IsHexPrefix(ReadOnlySpan< char > str, int i)
static bool TryParseGuid(ReadOnlySpan< char > guidString, ref GuidResult result)
static bool TryParseExactB(ReadOnlySpan< char > guidString, ref GuidResult result)
static bool operator==(Guid a, Guid b)
static bool TryParseExactN(ReadOnlySpan< char > guidString, ref GuidResult result)
static unsafe int HexsToCharsHexOutput(char *guidChars, int a, int b)
static bool TryParseHex(ReadOnlySpan< char > guidString, out ushort result, ref bool overflow)
Guid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)
static bool TryParse(ReadOnlySpan< char > input, out Guid result)
override string ToString()
static bool TryParseHex(ReadOnlySpan< char > guidString, out uint result)
Guid(ReadOnlySpan< byte > b)
static Guid ParseExact(ReadOnlySpan< char > input, ReadOnlySpan< char > format)
int CompareTo(Guid value)
static readonly Guid Empty
static Guid Parse(string input)
static bool TryParseExactP(ReadOnlySpan< char > guidString, ref GuidResult result)
int CompareTo(object? value)
static bool TryParseExactD(ReadOnlySpan< char > guidString, ref GuidResult result)
bool TryWriteBytes(Span< byte > destination)
ReadOnlySpan< T > Slice(int start)