private static bool TryParseExactD(ReadOnlySpan <char> guidString, ref Guid.GuidResult result) { if (guidString.Length != 36) { result.SetFailure(false, "Format_GuidInvLen"); return(false); } if (guidString[8] != '-' || guidString[13] != '-' || (guidString[18] != '-' || guidString[23] != '-')) { result.SetFailure(false, "Format_GuidDashes"); return(false); } ref Guid local = ref result._parsedGuid;
private static bool TryParseExactB(ReadOnlySpan <char> guidString, ref Guid.GuidResult result) { if (guidString.Length == 38 && guidString[0] == '{' && guidString[37] == '}') { return(Guid.TryParseExactD(guidString.Slice(1, 36), ref result)); } result.SetFailure(false, "Format_GuidInvLen"); return(false); }
private static bool TryParseGuid(ReadOnlySpan <char> guidString, ref Guid.GuidResult result) { guidString = guidString.Trim(); if (guidString.Length == 0) { result.SetFailure(false, "Format_GuidUnrecognized"); return(false); } switch (guidString[0]) { case '(': return(Guid.TryParseExactP(guidString, ref result)); case '{': return(!guidString.Contains <char>('-') ? Guid.TryParseExactX(guidString, ref result) : Guid.TryParseExactB(guidString, ref result)); default: return(!guidString.Contains <char>('-') ? Guid.TryParseExactN(guidString, ref result) : Guid.TryParseExactD(guidString, ref result)); } }