Table Results
Markdown tables can be created using the ToTableResult extension method.
Any type that extends IEnumerable<> can be used.
If the type is a simple type it is rendered in a single column like this,
// some simple data which will convert to a table
IEnumerable<int?> data = Enumerable.Range(1, 3).OfType<int?>().Append(element: null);
string tableResult = data.ToTableResult(defaultWhenNull: " - ");
Building the following table,
| x |
|---|
| 1 |
| 2 |
| 3 |
| - |
Multi column tables can be created from POCOs and Anonymous types like this,
// some complex data which will convert to a table
var data = Enumerable
.Range(1, 3)
.Select(i => new
{
Name = $"Name {i}",
Id = i,
Nested = new { ChildId = i + 1 },
});
string tableResult = data.ToTableResult();
Building a table like this,
| Name | Id | Nested |
|---|---|---|
| Name 1 | 1 | {"ChildId":2} |
| Name 2 | 2 | {"ChildId":3} |
| Name 3 | 3 | {"ChildId":4} |
Nested complex types are serialized using JSON.