예제 #1
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);
        }
        /// <summary>
        /// Is
        /// </summary>
        /// <param name="str"></param>
        /// <param name="style"></param>
        /// <param name="formatProvider"></param>
        /// <param name="dtAct"></param>
        /// <returns></returns>
        public static bool Is(string str,
                              DateTimeStyles style           = DateTimeStyles.None,
                              IFormatProvider formatProvider = null,
                              Action <DateTimeOffset> dtAct  = null)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return(false);
            }
            var result = DateTimeOffset.TryParse(str, formatProvider.SafeDateTime(), style, out var dateTimeOffset);

            if (!result)
            {
                result = ValueDeterminer.IsXxxAgain <DateTimeOffset>(str);
            }
            if (result)
            {
                dtAct?.Invoke(dateTimeOffset);
            }
            return(result);
        }
예제 #3
0
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="guidAct"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, Guid> > tries, Action <Guid> guidAct = null) =>
 ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace, Is, tries, guidAct);
예제 #4
0
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <param name="floatAct"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, float> > tries,
                       NumberStyles style = NUMBER_STYLES, IFormatProvider formatProvider = null, Action <float> floatAct = null)
 {
     return(ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace,
                                  (s, act) => Is(s, style, formatProvider.SafeNumber(), act), tries, floatAct));
 }
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="ignoreCase"></param>
 /// <param name="enumAct"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, TEnum> > tries, bool ignoreCase = false, Action <TEnum> enumAct = null) =>
 ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace, (s, act) => Is(s, ignoreCase, act), tries, enumAct);
예제 #6
0
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="encodingAction"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, Encoding> > tries, Action <Encoding> encodingAction = null)
 {
     return(ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace, Is, tries, encodingAction));
 }
예제 #7
0
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="style"></param>
 /// <param name="formatProvider"></param>
 /// <param name="byteAct"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, sbyte> > tries,
                       NumberStyles style = NumberStyles.Integer, IFormatProvider formatProvider = null, Action <sbyte> byteAct = null)
 {
     return(ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace,
                                  (s, act) => Is(s, style, formatProvider.SafeNumber(), act), tries, byteAct));
 }
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="addressAct"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, IPAddress> > tries, Action <IPAddress> addressAct = null) =>
 ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace, Is, tries, addressAct);
 /// <summary>
 /// Is
 /// </summary>
 /// <param name="str"></param>
 /// <param name="tries"></param>
 /// <param name="formatProvider"></param>
 /// <param name="dtAct"></param>
 /// <returns></returns>
 public static bool Is(string str, IEnumerable <IConversionTry <string, TimeSpan> > tries,
                       IFormatProvider formatProvider = null, Action <TimeSpan> dtAct = null)
 {
     return(ValueDeterminer.IsXXX(str, string.IsNullOrWhiteSpace,
                                  (s, act) => Is(s, formatProvider, act), tries, dtAct));
 }