示例#1
0
        public T[] List <T>(DbDataReader dr, List <string> columns = null)
        {
            List <T> list = new List <T>();

            while (dr.Read())
            {
                T md = Activator.CreateInstance <T>();
                lib.Class.Reflection rfc  = new lib.Class.Reflection(md);
                string[]             cols = rfc.GetProperties();

                for (int i = 0; i < cols.Length; i++)
                {
                    int ordinal = -1;
                    if (columns == null)
                    {
                        ordinal = dr.GetOrdinal(cols[i]);
                    }
                    else
                    {
                        ordinal = columns.IndexOf(cols[i].ToUpper());
                    }

                    if (ordinal >= 0)
                    {
                        string columnName  = cols[i];
                        object columnValue = dr.GetValue(ordinal);
                        rfc.SetAttibute(columnName, columnValue);
                    }
                }
                list.Add(md);
                DbBase.OnLineCounter();
            }
            return(list.ToArray());
        }
示例#2
0
 public void FillObject(DataRow dr, object Obj)
 {
     lib.Class.Reflection oa = new lib.Class.Reflection(Obj);
     for (int i = 0; i < dr.Table.Columns.Count; i++)
     {
         string ColName = dr.Table.Columns[i].ColumnName;
         oa.SetAttibute(ColName, dr[ColName].ToString());
     }
 }