Пример #1
0
        public static BinaryOutput PrintTable(TableOutput table)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<table>");

            // header
            sb.Append("<thead>");
            sb.Append("<tr>");

            foreach (var col in table.Columns)
            {
                sb.Append("<th>");
                sb.Append(htmlEncode(col));
                sb.Append("</th>");
            }

            sb.Append("</tr>");
            sb.Append("</thead>");

            // body
            sb.Append("<tbody>");

            foreach (var row in table.Rows)
            {
                sb.Append("<tr>");

                foreach (var cell in row)
                {
                    sb.Append("<td>");
                    sb.Append(htmlEncode(cell));
                    sb.Append("</td>");
                }

                sb.Append("</tr>");
            }

            sb.Append("</tbody>");

            sb.Append("</table>");
            var output = new BinaryOutput()
            {
                ContentType = "text/html", Data = sb.ToString()
            };

            return(output);
        }
Пример #2
0
        public static TableOutput AsTable <T>(this IEnumerable <T> list, List <string> propertyNames = null)
        {
            var table = new TableOutput();

            PropertyInfo[] properties = typeof(T).GetProperties();

            if (propertyNames != null && propertyNames.Count > 0)
            {
                properties = properties
                             .Where(p => propertyNames.Contains(p.Name))
                             .Select(p => p).ToArray();
            }

            table.Columns = properties.Select(p => p.Name).ToList();
            table.Rows    = new List <List <string> >();

            foreach (var i in list)
            {
                var row = MakeRowFormObject(i, properties);
                table.Rows.Add(row);
            }

            return(table);
        }