标签:style blog http color os ar for sp div
public static IList<T> ReaderToList<T>(this IDataReader dr) { //DateTime dt = DateTime.Now; using (dr) { List<T> list = new List<T>(); Type modelType = typeof(T); int count = dr.FieldCount; while (dr.Read()) { T model = Activator.CreateInstance<T>(); for (int i = 0; i < count; i++) { if (!IsNullOrDBNull(dr[i])) {//GetPropertyName PropertyInfo pi = modelType.GetProperty(dr.GetName(i), BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (pi != null) { pi.SetValue(model, HackType(dr[i], pi.PropertyType), null); // pi.SetValue(model, Convert.ChangeType(dr[i], pi.PropertyType), null); } } } list.Add(model); } // DateTime dt2 = DateTime.Now; // Logger logInfo = NLog.LogManager.GetLogger("filter"); // logInfo.Info("List:" + (dt2 - dt).TotalSeconds); return list; } }
标签:style blog http color os ar for sp div
原文地址:http://www.cnblogs.com/lihongchen/p/4025898.html