Ejemplo n.º 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());
        }
Ejemplo n.º 2
0
        public void Assign(object o)
        {
            lib.Class.Reflection foParam = new lib.Class.Reflection(o);

            string[] flds = foParam.GetFields();
            for (int i = 0; i < flds.Length; i++)
            {
                foThis.SetField(flds[i], foParam.GetFieldValue(flds[i]));
            }

            string[] prps = foParam.GetProperties();
            for (int i = 0; i < prps.Length; i++)
            {
                foThis.SetProperty(prps[i], foParam.GetPropertyValue(prps[i]));
            }
        }