using System; using System.Collections.Generic; using System.Linq; namespace Terminal.Gui { /// /// implementation that wraps arbitrary data. /// /// public class EnumerableTableSource : ITableSource { private T [] data; private string [] cols; private Dictionary> lamdas; /// /// Creates a new instance of the class that presents /// collection as a table. /// /// The elements of the collection are recorded during /// construction (immutable) but the properties of those objects are permitted to /// change. /// The data that you want to present. The members of this collection /// will be frozen after construction. /// /// Getter methods for each property you want to present in the table. For example: /// /// new () { /// { "Colname1", (t)=>t.SomeField}, /// { "Colname2", (t)=>t.SomeOtherField} ///} /// public EnumerableTableSource (IEnumerable data, Dictionary> columnDefinitions) { this.data = data.ToArray (); this.cols = columnDefinitions.Keys.ToArray (); this.lamdas = columnDefinitions; } /// public object this [int row, int col] { get => this.lamdas [ColumnNames [col]] (this.data [row]); } /// public int Rows => data.Length; /// public int Columns => cols.Length; /// public string [] ColumnNames => cols; } }