Exemplo n.º 1
0
        public static IList <T> MapList <T>(DataTable dataTable) where T : new()
        {
            DataTable dt   = dataTable;
            IList <T> list = new List <T>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    T obj = new T();
                    foreach (DataColumn col in dt.Columns)
                    {
                        CDataMapper.SetPropertyValue(obj, col.ColumnName, row[col]);
                    }
                    list.Add(obj);
                }
            }

            return(list);
        }
Exemplo n.º 2
0
        public static IList <TTarget> MapReader <TTarget>(string sql, CommandType CommandType,
                                                          params DbParameter[] Parameters) where TTarget : new()
        {
            IDataReader reader = ExecuteReader(sql, CommandType.StoredProcedure, Parameters);

            ValidateMappings <TTarget>(reader);

            IList <TTarget> list = new List <TTarget>();

            while (reader.Read())
            {
                TTarget obj = new TTarget();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetValue(i) != DBNull.Value)
                    {
                        CDataMapper.SetPropertyValue(obj, reader.GetName(i), reader.GetValue(i));
                    }
                }
                list.Add(obj);
            }
            reader.Close();
            return(list);
        }
Exemplo n.º 3
0
        public static IList <T> MapList <T>(string xmlData) where T : new()
        {
            DataSet ds = new DataSet();

            ds.ReadXml(new StringReader(xmlData));

            IList <T> list = new List <T>();

            if (ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                foreach (DataRow row in dt.Rows)
                {
                    T obj = new T();
                    foreach (DataColumn col in dt.Columns)
                    {
                        CDataMapper.SetPropertyValue(obj, col.ColumnName, row[col]);
                    }
                    list.Add(obj);
                }
            }

            return(list);
        }