/// <summary>
        /// Cast to
        /// </summary>
        /// <param name="str"></param>
        /// <param name="type"></param>
        /// <param name="ignoreCase"></param>
        /// <param name="format"></param>
        /// <param name="numberStyles"></param>
        /// <param name="dateTimeStyles"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static object CastToNullable(this string str, Type type, IgnoreCase ignoreCase,
                                            string format = null, NumberStyles?numberStyles = null, DateTimeStyles?dateTimeStyles = null,
                                            IFormatProvider formatProvider = null)
        {
            object result = default;

            return(str.IsNullable(type, (t) => result = t, () => result = null,
                                  ignoreCase.X(), format, numberStyles, dateTimeStyles, formatProvider)
                ? result
                : null);
        }
        /// <summary>
        /// Cast to
        /// </summary>
        /// <param name="str"></param>
        /// <param name="ignoreCase"></param>
        /// <param name="format"></param>
        /// <param name="numberStyles"></param>
        /// <param name="dateTimeStyles"></param>
        /// <param name="formatProvider"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T?CastToNullable <T>(this string str, IgnoreCase ignoreCase,
                                           string format = null, NumberStyles?numberStyles = null, DateTimeStyles?dateTimeStyles = null,
                                           IFormatProvider formatProvider = null) where T : struct
        {
            T?result = default;

            return(str.IsNullable <T>((t) => result = t, () => result = null,
                                      ignoreCase.X(), format, numberStyles, dateTimeStyles, formatProvider)
                ? result
                : null);
        }
Beispiel #3
0
 public static bool __enumIs(string s, Type type, Action <object> action, IgnoreCase ignoreCase) =>
 type.IsEnum && StringEnumDeterminer.Is(s, type, ignoreCase.X(), action);