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));
 }
Beispiel #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)));
        }
Beispiel #3
0
 public static IOption <Guid> ToGuid(this string s)
 {
     return(Tryer.Invoke <string, Guid>(Guid.TryParse, s));
 }
Beispiel #4
0
 public static IOption <TimeSpan> ToTimeSpan(this string s, IFormatProvider format = null)
 {
     return(Tryer.Invoke <string, IFormatProvider, TimeSpan>(TimeSpan.TryParse, s, format));
 }
Beispiel #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));
 }
Beispiel #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));
 }
Beispiel #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));
 }
Beispiel #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));
 }
Beispiel #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));
 }
Beispiel #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));
 }
Beispiel #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));
 }