DataTableSource.cs 1009 B

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