/// <summary>Converts the string to a postal code. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="s"> /// A string containing a postal code to convert. /// </param> /// <param name="formatProvider"> /// The specified format provider. /// </param> /// <param name="result"> /// The result of the parsing. /// </param> /// <returns> /// True if the string was converted successfully, otherwise false. /// </returns> public static bool TryParse(string s, IFormatProvider formatProvider, out PostalCode result) { result = default; if (string.IsNullOrEmpty(s)) { return(true); } var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture; if (Qowaiv.Unknown.IsUnknown(s, culture)) { result = Unknown; return(true); } if (Pattern.IsMatch(s)) { result = new PostalCode(Parsing.ClearSpacingAndMarkupToUpper(s)); return(true); } return(false); }
/// <summary>Converts the string to a postal code. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="s"> /// A string containing a postal code to convert. /// </param> /// <param name="formatProvider"> /// The specified format provider. /// </param> /// <param name="result"> /// The result of the parsing. /// </param> /// <returns> /// True if the string was converted successfully, otherwise false. /// </returns> public static bool TryParse(string s, IFormatProvider formatProvider, out PostalCode result) { result = PostalCode.Empty; if (string.IsNullOrEmpty(s)) { return(true); } var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture; if (Qowaiv.Unknown.IsUnknown(s, culture)) { result = PostalCode.Unknown; return(true); } if (IsValid(s, formatProvider)) { result = new PostalCode() { m_Value = Parsing.ClearSpacingAndMarkupToUpper(s) }; return(true); } return(false); }