-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintTable.cs
More file actions
58 lines (53 loc) · 1.67 KB
/
Copy pathPrintTable.cs
File metadata and controls
58 lines (53 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections.Generic;
using System.Linq;
namespace nyoka_Client
{
public class PrintTable : System.Collections.IEnumerable
{
public class ColumnCountException : System.Exception
{
public ColumnCountException()
: base()
{
}
}
internal List<string> columnNames = new List<string>();
internal List<int> columnWidths = new List<int>();
internal List<List<string>> rows = new List<List<string>>();
public PrintTable()
{
}
// To enable object initializer
public void Add(string columnName, int minWidth)
{
columnNames.Add(columnName);
int maxWidth = columnName.Length > minWidth ? columnName.Length : minWidth;
columnWidths.Add(maxWidth);
}
// To enable object initializer
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
yield break;
}
public void addRow(params string[] row)
{
if (row.Length != this.columnWidths.Count)
{
throw new ColumnCountException();
}
this.rows.Add(row.ToList());
// expand table if necessary
for (int i = 0; i < columnWidths.Count; i++)
{
if (row[i].Length > columnWidths[i])
{
columnWidths[i] = row[i].Length;
}
}
}
public static string doFormat(string input)
{
return ' ' + input + ' ';
}
}
}