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(); } }
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); }
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); }
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; }
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(); } }
// 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(); } }