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 = ; 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;
}
}