/// <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); }
static SoBase() { Props = DynamicProperties.CreatePropertyMethods(typeof(T)); }
static KeyValueDtoMap() { // this property collection is built only once Props = new List <DynamicProperties.Property>(DynamicProperties.CreatePropertyMethods(typeof(T))); KvMap = new Dictionary <string, string>(); }