示例#1
0
        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);
            }
        }
示例#2
0
 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
     }
 }
示例#3
0
 public TableView(TableRenderOptions options = null)
 {
     RenderOptions = options ?? new TableRenderOptions();
 }
示例#4
0
 public TableView(string[][] contents, TableRenderOptions options = null) : this(contents.Select(o => o.ToList()).ToList(), options)
 {
 }
示例#5
0
 public DynamicTableView(IEnumerable <TSource> source, TableRenderOptions options = null) : this(options)
 {
     Contents.AddRange(source);
 }