예제 #1
0
        /// <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);
        }
예제 #2
0
파일: Month.cs 프로젝트: hanifhn/Qowaiv
        /// <summary>Converts the string to a month.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">
        /// A string containing a month 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 Month result)
        {
            result = Month.Empty;
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }
            var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture;

            if (Qowaiv.Unknown.IsUnknown(s, culture))
            {
                result = Month.Unknown;
                return(true);
            }
            if (Pattern.IsMatch(s))
            {
                result = new Month()
                {
                    m_Value = Byte.Parse(s, formatProvider)
                };
                return(true);
            }
            else
            {
                AddCulture(culture);

                Byte m;
                var  str = Parsing.ToUnified(s);
                if (Parsings[culture].TryGetValue(str, out m) ||
                    Parsings[CultureInfo.InvariantCulture].TryGetValue(str, out m))
                {
                    result = new Month()
                    {
                        m_Value = m
                    };
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
        /// <summary>Converts the string to a Gender.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">
        /// A string containing a Gender 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 Gender result)
        {
            result = Empty;
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }
            var c = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture;

            AddCulture(c);

            var str = Parsing.ToUnified(s);

            if (Parsings[c].TryGetValue(str, out byte val) || Parsings[CultureInfo.InvariantCulture].TryGetValue(str, out val))
            {
                result = new Gender {
                    m_Value = val
                };
                return(true);
            }
            return(false);
        }
예제 #4
0
        /// <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);
        }