public T GetFieldValue <T>(string fieldName) { object val = GetFieldValue(fieldName); Type type = typeof(T); return((T)Common_liby.Convert2Type(type, val)); }
/// <summary> /// 数据类型转换 /// </summary> /// <param name="type">类型</param> /// <param name="val">数据值</param> /// <returns></returns> public static object Convert2Type(Type type, object val) { if (string.IsNullOrWhiteSpace(val?.ToString()) && type.IsValueType) { return(DBNull.Value); } //val = val.ToString(); //先转换成String类型再进行转换 if (val is DBNull) { return(null); } else if (type == typeof(BoundaryPoint)) { return(null); } else { return(Common_liby.Convert2Type(type, val)); } }
/// <summary> /// 数据类型转换 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="val">数据值</param> /// <returns></returns> public static T Convert2Type <T>(object val) { return(Common_liby.Convert2Type <T>(val)); }