Skip to content

Commit

Permalink
Right align numbers
Browse files Browse the repository at this point in the history
Resolves issue #3
  • Loading branch information
jpierson committed Apr 3, 2021
1 parent a099117 commit be04c32
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/ToMarkdownTable/LinqMarkdownTableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,28 @@ public static string ToMarkdownTable<T>(this IEnumerable<T> source)
var columnNames = gettables.Select(p => p.Name);

var headerLine = "| " + string.Join(" | ", columnNames.Select((n, i) => n.PadRight(maxColumnValues[i]))) + " |";
var headerDataDividerLine = "| " + string.Join(" | ", gettables.Select((n, i) => new string('-', maxColumnValues[i]))) + " |";

var isNumeric = new Func<Type, bool>(type =>
type == typeof(Byte) ||
type == typeof(SByte) ||
type == typeof(UInt16) ||
type == typeof(UInt32) ||
type == typeof(UInt64) ||
type == typeof(Int16) ||
type == typeof(Int32) ||
type == typeof(Int64) ||
type == typeof(Decimal) ||
type == typeof(Double) ||
type == typeof(Single));

var rightAlign = new Func<Type, char>(type => isNumeric(type) ? ':' : ' ');

var headerDataDividerLine =
"| " +
string.Join(
"| ",
gettables.Select((g, i) => new string('-', maxColumnValues[i]) + rightAlign(g.Type))) +
"|";

var lines = new[]
{
Expand Down

0 comments on commit be04c32

Please sign in to comment.