using System; using System.Data; namespace Infrastructure.Extensions { public static class DataTableExtensions { public static DataTable SetHeaders(this DataTable dataTable, params string[] headers) { if (dataTable is null) { throw new ArgumentNullException(nameof(dataTable)); } foreach (var item in headers) { dataTable.Columns.Add(new DataColumn(item)); } return dataTable; } public static DataTable Add(this DataSet dataSet, string tableName, params string[] headers) { if (dataSet is null) { throw new ArgumentNullException(nameof(dataSet)); } if (tableName is null) { throw new ArgumentNullException(nameof(tableName)); } var dataTable = dataSet.Tables.Add(); dataTable.TableName = tableName; return dataTable.SetHeaders(headers); } } }