コード例 #1
0
 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);
 }
コード例 #2
0
 public Guid(string g)
 {
     if (g == null)
     {
         throw new ArgumentNullException(nameof(g));
     }
     Guid.GuidResult result = new Guid.GuidResult(Guid.GuidParseThrowStyle.All);
     Guid.TryParseGuid((ReadOnlySpan <char>)g, ref result);
     this = result._parsedGuid;
 }
コード例 #3
0
 public static bool TryParse(ReadOnlySpan <char> input, out Guid result)
 {
     Guid.GuidResult result1 = new Guid.GuidResult(Guid.GuidParseThrowStyle.None);
     if (Guid.TryParseGuid(input, ref result1))
     {
         result = result1._parsedGuid;
         return(true);
     }
     result = new Guid();
     return(false);
 }
コード例 #4
0
 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;
コード例 #5
0
        public static bool TryParseExact(
            ReadOnlySpan <char> input,
            ReadOnlySpan <char> format,
            out Guid result)
        {
            if (format.Length != 1)
            {
                result = new Guid();
                return(false);
            }
            input = input.Trim();
            Guid.GuidResult result1 = new Guid.GuidResult(Guid.GuidParseThrowStyle.None);
            bool            flag    = false;

            switch ((char)((uint)format[0] | 32U))
            {
            case 'b':
                flag = Guid.TryParseExactB(input, ref result1);
                break;

            case 'd':
                flag = Guid.TryParseExactD(input, ref result1);
                break;

            case 'n':
                flag = Guid.TryParseExactN(input, ref result1);
                break;

            case 'p':
                flag = Guid.TryParseExactP(input, ref result1);
                break;

            case 'x':
                flag = Guid.TryParseExactX(input, ref result1);
                break;
            }
            if (flag)
            {
                result = result1._parsedGuid;
                return(true);
            }
            result = new Guid();
            return(false);
        }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
        public static Guid ParseExact(ReadOnlySpan <char> input, ReadOnlySpan <char> format)
        {
            if (format.Length != 1)
            {
                throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
            }
            input = input.Trim();
            Guid.GuidResult result = new Guid.GuidResult(Guid.GuidParseThrowStyle.AllButOverflow);
            bool            flag;

            switch ((char)((uint)format[0] | 32U))
            {
            case 'b':
                flag = Guid.TryParseExactB(input, ref result);
                break;

            case 'd':
                flag = Guid.TryParseExactD(input, ref result);
                break;

            case 'n':
                flag = Guid.TryParseExactN(input, ref result);
                break;

            case 'p':
                flag = Guid.TryParseExactP(input, ref result);
                break;

            case 'x':
                flag = Guid.TryParseExactX(input, ref result);
                break;

            default:
                throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
            }
            return(result._parsedGuid);
        }
コード例 #8
0
 public static Guid Parse(ReadOnlySpan <char> input)
 {
     Guid.GuidResult result = new Guid.GuidResult(Guid.GuidParseThrowStyle.AllButOverflow);
     Guid.TryParseGuid(input, ref result);
     return(result._parsedGuid);
 }