DataTableSource.cs 1.0 KB

123456789101112131415161718192021222324252627282930
  1. #nullable disable
  2. using System.Data;
  3. namespace Terminal.Gui.Views;
  4. /// <summary>
  5. /// <see cref="ITableSource"/> implementation that wraps a <see cref="System.Data.DataTable"/>. This class is
  6. /// mutable: changes are permitted to the wrapped <see cref="System.Data.DataTable"/>.
  7. /// </summary>
  8. public class DataTableSource : ITableSource
  9. {
  10. /// <summary>Creates a new instance based on the data in <paramref name="table"/>.</summary>
  11. /// <param name="table"></param>
  12. public DataTableSource (DataTable table) { DataTable = table; }
  13. /// <summary>The data table this source wraps.</summary>
  14. public DataTable DataTable { get; }
  15. /// <inheritdoc/>
  16. public object this [int row, int col] => DataTable.Rows [row] [col];
  17. /// <inheritdoc/>
  18. public int Rows => DataTable.Rows.Count;
  19. /// <inheritdoc/>
  20. public int Columns => DataTable.Columns.Count;
  21. /// <inheritdoc/>
  22. public string [] ColumnNames => DataTable.Columns.Cast<DataColumn> ().Select (c => c.Caption).ToArray ();
  23. }