public TableView(IEnumerable <object> source, string[] properties, TableRenderOptions options = null) { RenderOptions = options ?? new TableRenderOptions(); Headers = properties.ToList(); // Add Column Header Row Type enumerableType = source.GetType().GetGenericArguments()[0]; var typeProps = enumerableType.GetProperties(); List <PropertyInfo> columns = new List <PropertyInfo>(); foreach (string header in Headers) { PropertyInfo typeProp = typeProps.FirstOrDefault(o => header.Equals(o.Name, StringComparison.OrdinalIgnoreCase)); if (typeProp != null) { columns.Add(typeProp); } else { Consoul.Write($"Couldn't find property by the name '{header}'.", ConsoleColor.Red); } } foreach (object sourceItem in source) { List <string> row = new List <string>(); foreach (PropertyInfo property in columns) { row.Add(property.GetValue(sourceItem).ToString()); } Contents.Add(row); } }
public TableView(IEnumerable <IEnumerable <string> > contents, TableRenderOptions options = null) : this(options) { Contents = contents.Select(o => o.ToList()).ToList(); if (Contents.Count > 0) { Headers = Contents[0]; Contents.RemoveAt(0); // Remove Header Row } }
public TableView(TableRenderOptions options = null) { RenderOptions = options ?? new TableRenderOptions(); }
public TableView(string[][] contents, TableRenderOptions options = null) : this(contents.Select(o => o.ToList()).ToList(), options) { }
public DynamicTableView(IEnumerable <TSource> source, TableRenderOptions options = null) : this(options) { Contents.AddRange(source); }