/// <summary>
 /// To
 /// </summary>
 /// <param name="str"></param>
 /// <param name="impls"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public static byte To(string str,
                       IEnumerable <IConversionImpl <string, byte> > impls,
                       NumberStyles style             = NumberStyles.Integer,
                       IFormatProvider formatProvider = null)
 {
     return(ValueConverter.ToXxx(str, (s, act) => Is(s, style, formatProvider.SafeNumber(), act), impls));
 }
Example #2
0
 /// <summary>
 /// To
 /// </summary>
 /// <param name="text"></param>
 /// <param name="impls"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public static double To(
     string text,
     IEnumerable <IConversionImpl <string, double> > impls,
     NumberStyles style             = NUMBER_STYLES,
     IFormatProvider formatProvider = null)
 {
     return(ValueConverter.ToXxx(text, (s, act) => Is(s, style, formatProvider.SafeNumber(), act), impls));
 }
Example #3
0
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="text"></param>
 /// <param name="tries"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <param name="matchedCallback"></param>
 /// <returns></returns>
 public static bool Is(
     string text,
     IEnumerable <IConversionTry <string, double> > tries,
     NumberStyles style              = NUMBER_STYLES,
     IFormatProvider formatProvider  = null,
     Action <double> matchedCallback = null)
 {
     return(ValueDeterminer.IsXXX(text, string.IsNullOrWhiteSpace,
                                  (s, act) => Is(s, style, formatProvider.SafeNumber(), act), tries, matchedCallback));
 }
Example #4
0
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <param name="intAct"></param>
 /// <returns></returns>
 public static bool Is(
     string str,
     IEnumerable <IConversionTry <string, int> > tries,
     NumberStyles style             = NumberStyles.Integer,
     IFormatProvider formatProvider = null,
     Action <int> intAct            = null)
 {
     return(ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace,
                                  (s, act) => Is(s, style, formatProvider.SafeNumber(), act), tries, intAct));
 }
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="text"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <param name="matchedCallback"></param>
 /// <returns></returns>
 public static bool Is(
     string text,
     NumberStyles style             = NumberStyles.Integer,
     IFormatProvider formatProvider = null,
     Action <short> matchedCallback = null)
 {
     if (string.IsNullOrWhiteSpace(text))
     {
         return(false);
     }
     return(short.TryParse(text, style, formatProvider.SafeNumber(), out var number)
            .IfFalseThenInvoke(ValueDeterminer.IsXxxAgain <short>, text)
            .IfTrueThenInvoke(matchedCallback, number));
 }
Example #6
0
 /// <summary>
 /// To
 /// </summary>
 /// <param name="str"></param>
 /// <param name="defaultVal"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public static float To(string str, float defaultVal = default,
                        NumberStyles style           = NUMBER_STYLES, IFormatProvider formatProvider = null)
 {
     if (float.TryParse(str, style, formatProvider.SafeNumber(), out var number))
     {
         return(number);
     }
     try
     {
         return(Convert.ToSingle(Convert.ToDecimal(str)));
     }
     catch
     {
         return(ValueConverter.ToXxxAgain(str, defaultVal));
     }
 }
Example #7
0
 /// <summary>
 /// To
 /// </summary>
 /// <param name="str"></param>
 /// <param name="defaultVal"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public static int To(string str, int defaultVal = default,
                      NumberStyles style         = NumberStyles.Integer, IFormatProvider formatProvider = null)
 {
     if (int.TryParse(str, style, formatProvider.SafeNumber(), out var number))
     {
         return(number);
     }
     try
     {
         return(Convert.ToInt32(Convert.ToDecimal(str)));
     }
     catch
     {
         return(ValueConverter.ToXxxAgain(str, defaultVal));
     }
 }
Example #8
0
        /// <summary>
        /// Is
        /// </summary>
        /// <param name="str"></param>
        /// <param name="style"></param>
        /// <param name="formatProvider"></param>
        /// <param name="floatAct"></param>
        /// <returns></returns>
        public static bool Is(string str, NumberStyles style = NUMBER_STYLES,
                              IFormatProvider formatProvider = null, Action <float> floatAct = null)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return(false);
            }
            var result = float.TryParse(str, style, formatProvider.SafeNumber(), out var number);

            if (!result)
            {
                result = ValueDeterminer.IsXxxAgain <float>(str);
            }
            if (result)
            {
                floatAct?.Invoke(number);
            }
            return(result);
        }
Example #9
0
        /// <summary>
        /// Is
        /// </summary>
        /// <param name="str"></param>
        /// <param name="style"></param>
        /// <param name="formatProvider"></param>
        /// <param name="byteAct"></param>
        /// <returns></returns>
        public static bool Is(string str, NumberStyles style = NumberStyles.Integer,
                              IFormatProvider formatProvider = null, Action <sbyte> byteAct = null)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return(false);
            }
            var result = sbyte.TryParse(str, style, formatProvider.SafeNumber(), out var number);

            if (!result)
            {
                result = ValueDeterminer.IsXxxAgain <sbyte>(str);
            }
            if (result)
            {
                byteAct?.Invoke(number);
            }
            return(result);
        }
Example #10
0
        /// <summary>
        /// To
        /// </summary>
        /// <param name="text"></param>
        /// <param name="defaultVal"></param>
        /// <param name="style"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static double To(
            string text,
            double defaultVal              = default,
            NumberStyles style             = NUMBER_STYLES,
            IFormatProvider formatProvider = null)
        {
            if (text is null)
            {
                return(defaultVal);
            }

            if (double.TryParse(text, style, formatProvider.SafeNumber(), out var number))
            {
                return(number);
            }

            return(Try.Create(() => Convert.ToDouble(Convert.ToDecimal(text)))
                   .Recover(_ => ValueConverter.ToXxxAgain(text, defaultVal))
                   .Value);
        }
Example #11
0
        /// <summary>
        /// To
        /// </summary>
        /// <param name="text"></param>
        /// <param name="defaultVal"></param>
        /// <param name="style"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static int To(
            string text,
            int defaultVal                 = default,
            NumberStyles style             = NumberStyles.Integer,
            IFormatProvider formatProvider = null)
        {
            if (text is null)
            {
                return(defaultVal);
            }

            if (int.TryParse(text, style, formatProvider.SafeNumber(), out var number))
            {
                return(number);
            }

            return(Try.Create(() => Convert.ToInt32(Convert.ToDecimal(text)))
                   .Recover(_ => ValueConverter.ToXxxAgain(text, defaultVal))
                   .Value);
        }
Example #12
0
 /// <summary>
 /// To
 /// </summary>
 /// <param name="str"></param>
 /// <param name="impls"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public static float To(string str, IEnumerable <IConversionImpl <string, float> > impls,
                        NumberStyles style = NUMBER_STYLES, IFormatProvider formatProvider = null) =>
 ValueConverter.ToXxx(str, (s, act) => Is(s, style, formatProvider.SafeNumber(), act), impls);
Example #13
0
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <param name="longAct"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, long> > tries,
                       NumberStyles style = NUMBER_STYLES, IFormatProvider formatProvider = null, Action <long> longAct = null)
 {
     return(ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace,
                                  (s, act) => Is(s, style, formatProvider.SafeNumber(), act), tries, longAct));
 }
 /// <summary>
 /// To
 /// </summary>
 /// <param name="str"></param>
 /// <param name="impls"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <returns></returns>
 public static ushort To(string str, IEnumerable <IConversionImpl <string, ushort> > impls,
                         NumberStyles style = NumberStyles.Integer, IFormatProvider formatProvider = null) =>
 ValueConverter.ToXxx(str, (s, act) => Is(s, style, formatProvider.SafeNumber(), act), impls);