C# Build Simple Html Table

Date: 2021-03-31
[HttpGet("api/snipper/saldo")]
public async Task<IActionResult> GetSnipperSaldoInfoHtml()
{
	var info = await GetSnipperSaldoInfo();
	var data = Select(
		Select<object>("Huidig snipper-saldo", FormatNumber(info.SaldoNow)),
		Select<object>("Huidig tijd-voor-tijd saldo", FormatNumber(info.SaldoTVT)),
		Select<object>("Saldo totaal dit jaar", FormatNumber(info.SaldoTotalThisYear))
	);
	return Content(GetHtmlTable(data), "text/html");
}

public static string FormatNumber(double d) => FormattableString.Invariant($"{Math.Round(d, 2):0.00}"); 

public static IEnumerable<T> Select<T>(params T[] args) => args;

private static string GetHtmlTable(IEnumerable<IEnumerable<object>> data)
{
	var sb = new StringBuilder();
	sb.AppendLine("<style>table {width: 300px;} td:nth-child(2) {text-align:right;}</style>");
	sb.AppendLine($"<table>");
	foreach(var row in data)
	{
		sb.AppendLine($"<tr>");
		foreach (var cell in row)
			sb.AppendLine($"<td>{cell}</td>");
		sb.AppendLine($"</tr>");
	}
	sb.AppendLine($"</table>");
	return sb.ToString();
}
48130cookie-checkC# Build Simple Html Table