Example #1
0
        public MyTable CreateMyDataTable <T>(IEnumerable <T> list)
        {
            Type    type       = typeof(T);
            var     properties = type.GetProperties();
            MyTable dataTable  = new MyTable();

            foreach (T entity in list)
            {
                MyRow    dataRow = new MyRow();
                object[] values  = new object[properties.Length];
                for (int i = 0; i < properties.Length; i++)
                {
                    string name     = properties[i].Name;
                    Type   typeCol  = Nullable.GetUnderlyingType(properties[i].PropertyType) ?? properties[i].PropertyType;
                    object valueCol = properties[i].GetValue(entity);

                    MyColumn dataColumn = new MyColumn(name, typeCol, valueCol);
                    dataRow.AddMyColumn(dataColumn);
                }
                dataTable.AddMyRow(dataRow);
            }
            return(dataTable);
        }
Example #2
0
 public void AddMyRow(MyRow row)
 {
     this.Rows.Add(row);
 }