Esempio n. 1
0
        public static Guid ParseExact(String input, String format)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (format.Length != 1)
            {
                // all acceptable format strings are of length 1
                throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
            }

            GuidStyles style;
            char       formatCh = format[0];

            if (formatCh == 'D' || formatCh == 'd')
            {
                style = GuidStyles.DigitFormat;
            }
            else if (formatCh == 'N' || formatCh == 'n')
            {
                style = GuidStyles.NumberFormat;
            }
            else if (formatCh == 'B' || formatCh == 'b')
            {
                style = GuidStyles.BraceFormat;
            }
            else if (formatCh == 'P' || formatCh == 'p')
            {
                style = GuidStyles.ParenthesisFormat;
            }
            else if (formatCh == 'X' || formatCh == 'x')
            {
                style = GuidStyles.HexFormat;
            }
            else
            {
                throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
            }

            GuidResult result = new GuidResult();

            result.Init(GuidParseThrowStyle.AllButOverflow);
            if (TryParseGuid(input, style, ref result))
            {
                return(result._parsedGuid);
            }
            else
            {
                throw result.GetGuidParseException();
            }
        }
Esempio n. 2
0
        public static Guid ParseExact(string input, string format)
        {
            GuidStyles digitFormat;

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            if (format.Length != 1)
            {
                throw new FormatException(Environment.GetResourceString("Format_InvalidGuidFormatSpecification"));
            }
            char ch = format[0];

            switch (ch)
            {
            case 'D':
            case 'd':
                digitFormat = GuidStyles.DigitFormat;
                break;

            case 'N':
            case 'n':
                digitFormat = GuidStyles.None;
                break;

            case 'B':
            case 'b':
                digitFormat = GuidStyles.BraceFormat;
                break;

            case 'P':
            case 'p':
                digitFormat = GuidStyles.ParenthesisFormat;
                break;

            default:
                if ((ch != 'X') && (ch != 'x'))
                {
                    throw new FormatException(Environment.GetResourceString("Format_InvalidGuidFormatSpecification"));
                }
                digitFormat = GuidStyles.HexFormat;
                break;
            }
            GuidResult result = new GuidResult();

            result.Init(GuidParseThrowStyle.AllButOverflow);
            if (!TryParseGuid(input, digitFormat, ref result))
            {
                throw result.GetGuidParseException();
            }
            return(result.parsedGuid);
        }
Esempio n. 3
0
        public static bool TryParseExact(String input, String format, out Guid result)
        {
            if (format == null || format.Length != 1)
            {
                result = Guid.Empty;
                return(false);
            }

            GuidStyles style;
            char       formatCh = format[0];

            if (formatCh == 'D' || formatCh == 'd')
            {
                style = GuidStyles.DigitFormat;
            }
            else if (formatCh == 'N' || formatCh == 'n')
            {
                style = GuidStyles.NumberFormat;
            }
            else if (formatCh == 'B' || formatCh == 'b')
            {
                style = GuidStyles.BraceFormat;
            }
            else if (formatCh == 'P' || formatCh == 'p')
            {
                style = GuidStyles.ParenthesisFormat;
            }
            else if (formatCh == 'X' || formatCh == 'x')
            {
                style = GuidStyles.HexFormat;
            }
            else
            {
                // invalid guid format specification
                result = Guid.Empty;
                return(false);
            }

            GuidResult parseResult = new GuidResult();

            parseResult.Init(GuidParseThrowStyle.None);
            if (TryParseGuid(input, style, ref parseResult))
            {
                result = parseResult._parsedGuid;
                return(true);
            }
            else
            {
                result = Guid.Empty;
                return(false);
            }
        }
Esempio n. 4
0
        public static bool TryParse(string input, out Guid result)
        {
            GuidResult result2 = new GuidResult();

            result2.Init(GuidParseThrowStyle.None);
            if (TryParseGuid(input, GuidStyles.Any, ref result2))
            {
                result = result2.parsedGuid;
                return(true);
            }
            result = Empty;
            return(false);
        }
Esempio n. 5
0
        public static bool TryParseExact(string input, string format, out Guid result)
        {
            GuidStyles digitFormat;

            if ((format == null) || (format.Length != 1))
            {
                result = Empty;
                return(false);
            }
            switch (format[0])
            {
            case 'D':
            case 'd':
                digitFormat = GuidStyles.DigitFormat;
                break;

            case 'N':
            case 'n':
                digitFormat = GuidStyles.None;
                break;

            case 'B':
            case 'b':
                digitFormat = GuidStyles.BraceFormat;
                break;

            case 'P':
            case 'p':
                digitFormat = GuidStyles.ParenthesisFormat;
                break;

            case 'X':
            case 'x':
                digitFormat = GuidStyles.HexFormat;
                break;

            default:
                result = Empty;
                return(false);
            }
            GuidResult result2 = new GuidResult();

            result2.Init(GuidParseThrowStyle.None);
            if (TryParseGuid(input, digitFormat, ref result2))
            {
                result = result2.parsedGuid;
                return(true);
            }
            result = Empty;
            return(false);
        }
Esempio n. 6
0
        public static Guid Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            GuidResult result = new GuidResult();

            result.Init(GuidParseThrowStyle.AllButOverflow);
            if (!TryParseGuid(input, GuidStyles.Any, ref result))
            {
                throw result.GetGuidParseException();
            }
            return(result.parsedGuid);
        }
Esempio n. 7
0
        public static bool TryParse(String input, out Guid result)
        {
            GuidResult parseResult = new GuidResult();

            parseResult.Init(GuidParseThrowStyle.None);
            if (TryParseGuid(input, GuidStyles.Any, ref parseResult))
            {
                result = parseResult._parsedGuid;
                return(true);
            }
            else
            {
                result = Guid.Empty;
                return(false);
            }
        }
Esempio n. 8
0
        public Guid(string g)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            this = Empty;
            GuidResult result = new GuidResult();

            result.Init(GuidParseThrowStyle.All);
            if (!TryParseGuid(g, GuidStyles.Any, ref result))
            {
                throw result.GetGuidParseException();
            }
            this = result.parsedGuid;
        }
Esempio n. 9
0
        public static Guid Parse(String input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            Contract.EndContractBlock();

            GuidResult result = new GuidResult();

            result.Init(GuidParseThrowStyle.AllButOverflow);
            if (TryParseGuid(input, GuidStyles.Any, ref result))
            {
                return(result._parsedGuid);
            }
            else
            {
                throw result.GetGuidParseException();
            }
        }
Esempio n. 10
0
        // Creates a new guid based on the value in the string.  The value is made up
        // of hex digits speared by the dash ("-"). The string may begin and end with
        // brackets ("{", "}").
        //
        // The string must be of the form dddddddd-dddd-dddd-dddd-dddddddddddd. where
        // d is a hex digit. (That is 8 hex digits, followed by 4, then 4, then 4,
        // then 12) such as: "CA761232-ED42-11CE-BACD-00AA0057B223"
        //
        public Guid(String g)
        {
            if (g == null)
            {
                throw new ArgumentNullException(nameof(g));
            }
            Contract.EndContractBlock();
            this = Guid.Empty;

            GuidResult result = new GuidResult();

            result.Init(GuidParseThrowStyle.All);
            if (TryParseGuid(g, GuidStyles.Any, ref result))
            {
                this = result._parsedGuid;
            }
            else
            {
                throw result.GetGuidParseException();
            }
        }