|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Kaleida.ServiceMonitor.Model.Email
{
internal class BasicTable
{
public class Row
{
private readonly List<IHtmlString> items;
public Row(IEnumerable<IHtmlString> items)
{
this.items = items.ToList();
}
public List<IHtmlString> Items
{
get { return items; }
}
}
private List<IHtmlString> headings = new List<IHtmlString>();
private readonly List<Row> rows = new List<Row>();
public void AddHeaderRow(IList<string> values)
{
AddHeaderRow(values.Select(i => i.HtmlEncode()).ToList());
}
public void AddHeaderRow(IList<IHtmlString> values)
{
if (rows.Any())
throw new InvalidOperationException("Must add Header row before Content");
headings = values.ToList();
}
public void AddRow(IList<string> values)
{
AddRow(values.Select(i => i.HtmlEncode()).ToList());
}
public void AddRow(IList<IHtmlString> values)
{
if (values.Count() != headings.Count())
throw new InvalidOperationException(string.Format("Expected {0} value(s) but received {1}", headings.Count(), values.Count()));
rows.Add(new Row(values));
}
public IList<IHtmlString> Headings
{
get { return headings.AsReadOnly(); }
}
public IList<Row> Rows
{
get { return rows.AsReadOnly(); }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Stuart Wheelwright is the Principal Architect and Software Developer at
BlackJet Software Ltd.
He has over 16 years commercial experience producing robust, maintainable, web-based solutions and bespoke systems for Microsoft platforms.
His latest project is
Shopping UK, an elegantly simple shopping list for iPhone.