Exemple #1
0
        /// <summary>
        /// ToObject
        /// </summary>
        /// <param name="input"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object ToObject(string input, Type type)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(null);
            }
            try
            {
                if (type.IsPrimitive || type == typeof(string) || type == typeof(DateTime))
                {
                    return(CUtils.Parse(input, type, null));
                }

                return(JsonConvert.DeserializeObject(input, type));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #2
0
 /// <summary>
 /// GetFieldValue
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <param name="name"></param>
 /// <param name="def"></param>
 /// <returns></returns>
 public static T GetFieldValue <T>(object obj, string name, T def = default(T))
 {
     return(CUtils.Parse(GetFieldValue(obj, name), def));
 }