public static bool TryGet <T, TCheck>([NotNull] this Hashtable thisValue, [NotNull] object key, T defaultValue, out T value, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, Func <string, T, T> whenFailed)
 {
     return(TryGet(thisValue, key, defaultValue, out value, beforeConvert, null, whenFailed));
 }
        public static bool TryGet <T, TCheck>([NotNull] this Hashtable thisValue, [NotNull] object key, T defaultValue, out T value, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, OutWithDefaultFunc <string, T, bool> beforeParse, Func <string, T, T> whenFailed)
        {
            if (!thisValue.ContainsKey(key))
            {
                value = defaultValue;
                return(false);
            }

            object v = thisValue[key];

            if (v.IsNull())
            {
                value = defaultValue;
                return(false);
            }

            value = v.To(defaultValue, beforeConvert, beforeParse, whenFailed);
            return(true);
        }
Example #3
0
        public static bool TryGet <T>([NotNull] this JObject thisValue, [NotNull] string name, T defaultValue, out T value, OutWithDefaultFunc <string, T, bool> beforeParse, Func <string, T, T> whenFailed)
        {
            if (!TryWalkPath(ref thisValue, ref name))
            {
                value = defaultValue;
                return(false);
            }

            if (!thisValue.TryGetValue(name, StringComparison.OrdinalIgnoreCase, out JToken token) ||
                token is not JValue jValue)
            {
                value = defaultValue;
                return(false);
            }

            value = jValue.Value.To(defaultValue, beforeParse, whenFailed);
            return(true);
        }
        public static T Get <T, TCheck>([NotNull] this Hashtable thisValue, [NotNull] object key, T defaultValue, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, OutWithDefaultFunc <string, T, bool> beforeParse, Func <string, T, T> whenFailed)
        {
            object value = thisValue[key];

            return(value.IsNull() ? defaultValue : value.To(defaultValue, beforeParse, whenFailed));
        }
Example #5
0
        public static T Get <T, TCheck>([NotNull] this JObject thisValue, [NotNull] string name, T defaultValue, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, OutWithDefaultFunc <string, T, bool> beforeParse, Func <string, T, T> whenFailed)
        {
            JObject obj = thisValue;
            string  nam = name;

            if (!WalkPath(ref obj, ref nam))
            {
                return(defaultValue);
            }
            return(obj.GetValue(nam, StringComparison.OrdinalIgnoreCase) is not JValue value
                                                ? defaultValue
                                                : value.To(defaultValue, beforeParse, whenFailed));
        }
Example #6
0
 public static T Get <T, TCheck>([NotNull] this JObject thisValue, [NotNull] string name, T defaultValue, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, Func <string, T, T> whenFailed)
 {
     return(Get(thisValue, name, defaultValue, beforeConvert, null, whenFailed));
 }
Example #7
0
        public static bool TryGet <T, TCheck>([NotNull] this DataRow thisValue, [NotNull] string name, T defaultValue, out T value, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, OutWithDefaultFunc <string, T, bool> beforeParse, Func <string, T, T> whenFailed)
        {
            if (!thisValue.Table.Columns.Contains(name))
            {
                value = defaultValue;
                return(false);
            }

            object v = thisValue[name];

            if (v.IsNull())
            {
                value = defaultValue;
                return(false);
            }

            value = v.To(defaultValue, beforeConvert, beforeParse, whenFailed);
            return(true);
        }
Example #8
0
 public static bool TryGet <T, TCheck>([NotNull] this DataRow thisValue, [NotNull] string name, T defaultValue, out T value, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, Func <string, T, T> whenFailed)
 {
     return(TryGet(thisValue, name, defaultValue, out value, beforeConvert, null, whenFailed));
 }
Example #9
0
        public static T Get <T, TCheck>([NotNull] this DataRow thisValue, [NotNull] string name, T defaultValue, OutWithDefaultFunc <TCheck, T, bool> beforeConvert, OutWithDefaultFunc <string, T, bool> beforeParse, Func <string, T, T> whenFailed)
        {
            object value = thisValue[name];

            return(value.IsNull() ? defaultValue : value.To(defaultValue, beforeParse, whenFailed));
        }