public static List <DynamicParameters> ToDapperList(this DataTable table, bool reverse = true, params string[] FilterField) { var modelList = new List <DynamicParameters>(); foreach (DataRow row in table.Rows) { var model = new DynamicParameters(); var dict = (IDictionary <string, object>)model; foreach (DataColumn column in table.Columns) { if (FilterField.Length != 0) { if (reverse == true) { if (!FilterField.Contains(column.ColumnName)) { dict[column.ColumnName] = row[column]; } } else { if (FilterField.Contains(column.ColumnName)) { dict[column.ColumnName] = row[column]; } } } else { dict[column.ColumnName] = row[column]; } } modelList.Add(model); } return(modelList); }
public static List <dynamic> ToDynamicList <T>(this DataTable table, bool reverse = true, params string[] FilterField) where T : class, new() { var modelList = new List <dynamic>(); foreach (DataRow row in table.Rows) { dynamic model = new ExpandoObject(); var dict = (IDictionary <string, object>)model; foreach (DataColumn column in table.Columns) { if (FilterField.Length != 0) { if (reverse == true) { if (!FilterField.Contains(column.ColumnName)) { dict[column.ColumnName] = row[column]; } } else { if (FilterField.Contains(column.ColumnName)) { dict[column.ColumnName] = row[column]; } } } else { dict[column.ColumnName] = row[column]; } } modelList.Add(model); } return(modelList); }