/// <summary> /// 根据列模型转换数据行为目标对象 /// </summary> /// <typeparam name="T">目标类型</typeparam> /// <param name="dr">数据行</param> /// <returns>目标对象</returns> public static T MToObjByColumnModelAttribute <T>(this DataRow dr) { var model = ConvertManager.GetDefultObject <T>(); if (model != null) { model.MSetValueByColumnModelAttribute(dr); } return(model == null ? default(T) : model); }
/// <summary> /// Json字符串转换对象 /// </summary> /// <typeparam name="T">目标对象类型</typeparam> /// <param name="jsonStr">Json字符串</param> /// <returns>转换后的对象</returns> public static T MJsonToObject <T>(this string jsonStr) { try { var model = ConvertManager.GetDefultObject <T>(); JsonConvert.PopulateObject(jsonStr, model); return(model); } catch (Exception ex) { throw new MConvertException("Json字符串有误", ex); } }
/// <summary> /// 获得默认对象 /// </summary> /// <typeparam name="T">要设置的类型</typeparam> /// <param name="obj">要设置的对象</param> /// <returns>默认对象</returns> public static T MGetDefultObject <T>(this object obj) { return(ConvertManager.GetDefultObject <T>()); }
/// <summary> /// 获得默认对象 /// </summary> /// <param name="obj">要设置的对象</param> /// <param name="type">要设置的类型</param> /// <returns>默认对象</returns> public static object MGetDefultObject(this object obj, Type type) { return(ConvertManager.GetDefultObject(type)); }