コード例 #1
0
 public static IOption <V> Get <K, V>(this IReadOnlyDictionary <K, V> dictionary, K key)
 {
     if (Equals(key, null))
     {
         return(Option.Empty <V>());
     }
     return(Tryer.Invoke <K, V>(dictionary.TryGetValue, key));
 }
コード例 #2
0
        public static IOption <TEnum> ToEnum <TEnum>(this string s, bool ignoreCase = false)
            where TEnum : struct
        {
            if (s == null || s.Contains(","))
            {
                return(Option.Empty <TEnum>());
            }
            var enumValue = Tryer.Invoke <string, bool, TEnum>(Enum.TryParse <TEnum>, s, ignoreCase);

            return(enumValue.Where(v => Enum.IsDefined(typeof(TEnum), v) && v.ToString().Equals(s, StringComparison.InvariantCultureIgnoreCase)));
        }
コード例 #3
0
 public static IOption <Guid> ToGuid(this string s)
 {
     return(Tryer.Invoke <string, Guid>(Guid.TryParse, s));
 }
コード例 #4
0
 public static IOption <TimeSpan> ToTimeSpan(this string s, IFormatProvider format = null)
 {
     return(Tryer.Invoke <string, IFormatProvider, TimeSpan>(TimeSpan.TryParse, s, format));
 }
コード例 #5
0
 public static IOption <DateTime> ToDateTime(this string s, IFormatProvider format = null, DateTimeStyles style = DateTimeStyles.None)
 {
     return(Tryer.Invoke <string, IFormatProvider, DateTimeStyles, DateTime>(DateTime.TryParse, s, format, style));
 }
コード例 #6
0
 public static IOption <bool> ToBool(this string s, IFormatProvider format = null, NumberStyles style = NumberStyles.Number)
 {
     return(Tryer.Invoke <string, bool>(Boolean.TryParse, s));
 }
コード例 #7
0
 public static IOption <decimal> ToDecimal(this string s, IFormatProvider format = null, NumberStyles style = NumberStyles.Number)
 {
     return(Tryer.Invoke <string, NumberStyles, IFormatProvider, decimal>(Decimal.TryParse, s, style, format));
 }
コード例 #8
0
 public static IOption <double> ToDouble(this string s, IFormatProvider format = null, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands)
 {
     return(Tryer.Invoke <string, NumberStyles, IFormatProvider, double>(Double.TryParse, s, style, format));
 }
コード例 #9
0
 public static IOption <long> ToLong(this string s, IFormatProvider format = null, NumberStyles style = NumberStyles.Integer)
 {
     return(Tryer.Invoke <string, NumberStyles, IFormatProvider, long>(Int64.TryParse, s, style, format));
 }
コード例 #10
0
 public static IOption <int> ToInt(this string s, IFormatProvider format = null, NumberStyles style = NumberStyles.Integer)
 {
     return(Tryer.Invoke <string, NumberStyles, IFormatProvider, int>(Int32.TryParse, s, style, format));
 }
コード例 #11
0
 public static IOption <byte> ToByte(this string s, IFormatProvider format = null, NumberStyles style = NumberStyles.Integer)
 {
     return(Tryer.Invoke <string, NumberStyles, IFormatProvider, byte>(Byte.TryParse, s, style, format));
 }