zoukankan      html  css  js  c++  java
  • IDataReader转换成list通用方法

     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;
                }
            }
    View Code
  • 相关阅读:
    viewpaper
    mfc ui 3 swf
    mfc ui3
    mfc ui2
    mfc ui库
    将Cocos2dX渲染到MFC窗口上
    MFC 框架技术简单研讨
    不可忽略的数据库缓存重建
    google bookmarket api
    android 加载大图片
  • 原文地址:https://www.cnblogs.com/lihongchen/p/4025898.html
Copyright © 2011-2022 走看看