예제 #1
0
        /// <summary>
        /// 将数据表转换成对象T
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="mappings"></param>
        /// <returns></returns>
        public List <T> Convert(DataTable dt, IInstanceCreater <T> creater, params ColumnMapping[] mappings)
        {
            List <T> list = new List <T>();

            if (dt == null)
            {
                return(list);
            }
            foreach (DataRow row in dt.Rows)
            {
                T    t    = creater.CreateInstance(row);
                Type type = t.GetType();

                foreach (ColumnMapping mapping in mappings)
                {
                    PropertyInfo pi = type.GetProperty(mapping.Property);
                    if (pi != null)
                    {
                        object obj = row[mapping.Column];
                        if (obj is DBNull)
                        {
                            obj = null;
                        }
                        pi.SetValue(t, obj);
                    }
                }

                list.Add(t);
            }
            return(list);
        }
예제 #2
0
 public UnityComponentPool(IInstanceCreater creater)
     : base(creater)
 {
 }