方法
/// <summary> /// 获取 obj value /// </summary> /// <param name="info">对象</param> /// <param name="field">对象内字段</param> /// <returns></returns> public static object GetDataValue( object info, string field) { try { if (info == null) return null; Type t = info.GetType(); IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi; return property.First().GetValue(info, null); } catch (Exception ex) { return null; } }
调用
object rsRes = null; rsRes = conn.QueryBySQLPage<object>(qsql, page, size, orderby); object TotalObj = MyAppApi.Comm.Commonly.GetDataValue(rsRes, "TotalNum");