/// <summary> /// Creates a "PlainTextTable" instance with the fields in this definition, for fixed length column plain text output /// </summary> /// <param name="rows">The rows of data to tabulate</param> /// <param name="tab">Optional, if specified adds the tabulated data to the table. A new instance will be created and returned if this is null.</param> /// <returns>Either the PlainTextTable instance that was passed in, or a new instance of a PlainTextTable, populated with the data from the rows.</returns> public PlainTextTable Tabulate(IEnumerable <T> rows, PlainTextTable tab = null) { if (null == tab) { tab = new PlainTextTable(); } var columns = this .Where( x => x.ShouldInclude ) .ToArray(); string[] line = columns .Select( x => x.Label ?? x.Key ) .ToArray(); tab.AddRow(line); // header foreach (T row in rows) { line = columns .Select( x => x.PickValue(row) ) .ToArray(); tab.AddRow(line); } return(tab); }
/// <summary> /// Creates a "PlainTextTable" instance with the fields in this definition, for fixed length column plain text output /// </summary> /// <param name="rows">The rows of data to tabulate</param> /// <param name="tab">Optional, if specified adds the tabulated data to the table. A new instance will be created and returned if this is null.</param> /// <returns>Either the PlainTextTable instance that was passed in, or a new instance of a PlainTextTable, populated with the data from the rows.</returns> public PlainTextTable Tabulate(IEnumerable <T> rows, PlainTextTable tab = null) { if (null == tab) { tab = new PlainTextTable(); } string[] line = this.Select(x => x.Key).ToArray(); tab.AddRow(line); // header foreach (T row in rows) { line = this.Select(x => x.Value(row)).ToArray(); tab.AddRow(line); } return(tab); }