Пример #1
0
        /// <summary>
        /// Convert IList to DataTable
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static DataTable ConvertTo <T>(IList <T> list)
        {
            DataTable table = CreateTable <T>();

            var fields = DynamicProperties.CreatePropertyMethods <T>();

            foreach (T item in list)
            {
                DataRow row = table.NewRow();
                foreach (DataColumn column in table.Columns)
                {
                    var field = fields.SingleOrDefault(f => f.Info.Name.Equals(column.ColumnName));
                    row[column.ColumnName] = field.Getter(item) ?? DBNull.Value;
                }
                table.Rows.Add(row);
            }

            return(table);
        }
Пример #2
0
 static SoBase()
 {
     Props = DynamicProperties.CreatePropertyMethods(typeof(T));
 }
Пример #3
0
 static KeyValueDtoMap()
 {
     // this property collection is built only once
     Props = new List <DynamicProperties.Property>(DynamicProperties.CreatePropertyMethods(typeof(T)));
     KvMap = new Dictionary <string, string>();
 }