/// <summary> /// 核心方法 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql"></param> /// <returns></returns> private static List <T> GetListBySql <T>(string sql) where T : new() { var type = typeof(T); var st = type.GetTblStruct(); var list = new List <T>(); using (var reader = DbHelperAccess.GetReader(sql)) { //组装数据 while (reader.Read()) { var t = new T(); foreach (var item in st.ListCol) { if (item.NotSearch) { continue; } object obj = reader[item.ColName]; var p = type.GetProperty(item.ClassColName); if (p != null) { var setValue = p.DealSetValue(obj); p.SetValue(t, setValue, null); } } list.Add(t); } } return(list); }