Beispiel #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);
        }
Beispiel #2
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);
        }