-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProgram.cs
More file actions
195 lines (150 loc) · 5.52 KB
/
Program.cs
File metadata and controls
195 lines (150 loc) · 5.52 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
namespace ConsoleTable.Text.Examples;
class Program
{
static void Main(string[] args)
{
WriteDefaultTable();
WriteDefaultTableWithProperties();
WriteTableWithStyling(true, true, 10);
WriteTableWithStyling(false, true, 10);
WriteTableWithStyling(true, false, 10);
WriteTableWithStyling(false, false, 10);
WriteTableWithoutHeaders();
WriteTableMoreHeaders();
WriteTableLessHeaders();
WriteTableEachRowRandom();
WriteTableFluent();
Console.Read();
}
private static void WriteDefaultTable()
{
Console.WriteLine();
Console.WriteLine("Default table:");
var table = new Table();
table.SetHeaders("Name", "Age", "City");
table.AddRow("Alice Cooper", "30", "New York");
table.AddRows(new string[][]
{
new string[] { "Bob", "25", "Los Angeles" },
new string[] { "Charlie Brown", "47", "Chicago" }
});
Console.WriteLine(table.ToTable());
Console.WriteLine();
}
private static void WriteDefaultTableWithProperties()
{
Console.WriteLine();
Console.WriteLine("Default table with properties instead of methods:");
var table = new Table
{
Headers = new string[] { "Name", "Age", "City" },
Rows = new List<string[]>
{
new string[] { "Alice Cooper", "30", "New York" },
new string[] { "Bob", "25", "Los Angeles" },
new string[] { "Charlie Brown", "47", "Chicago" }
}
};
Console.WriteLine(table.ToTable());
Console.WriteLine();
}
private static void WriteTableWithoutHeaders()
{
Console.WriteLine();
Console.WriteLine("Table without headers:");
var table = new Table();
for (int i = 1; i <= 5; i++)
table.AddRow($"name {i}", (i * 15).ToString());
Console.WriteLine(table.ToString());
Console.WriteLine();
}
private static void WriteTableMoreHeaders()
{
Console.WriteLine();
Console.WriteLine("Table with more headers:");
var table = new Table();
table.SetHeaders("Name", "Age", "City", "Country");
table.AddRows(
new string[] { "Alice Cooper", "30" },
new string[] { "Bob", "25" },
new string[] { "Charlie Brown", "47" }
);
Console.WriteLine(table.ToString());
Console.WriteLine();
}
private static void WriteTableLessHeaders()
{
Console.WriteLine();
Console.WriteLine("Table with less headers:");
var table = new Table();
table.SetHeaders("Name");
table.AddRows(
new string[] { "Alice Cooper", "30", "New York" },
new string[] { "Bob", "25", "Los Angeles" },
new string[] { "Charlie Brown", "47", "Chicago" }
);
Console.WriteLine(table.ToString());
Console.WriteLine();
}
private static void WriteTableEachRowRandom()
{
Console.WriteLine();
Console.WriteLine("Table with random row column count:");
var table = new Table();
table.SetHeaders("Name", "Age", "City");
table.AddRow("Alice");
table.AddRow("Bob", "25", "Antwerp", "Belgium");
table.AddRow("Charlie", "47", "Chicago");
table.AddRow("Karina", "33", "Lima", "Peru", "South-America");
table.AddRow("Jenny", "43");
table.AddRow("John");
table.AddRow("Johny");
table.AddRow();
table.AddRow(null!);
table.AddRow("Thomas", "33", "Brussels", "Belgium", "Europe", "Earth", "Solar System");
table.AddRow("Nathalie", "29", "Paris", "France", "Europe", "Earth", "Solar System");
table.AddRow("Mathias", "37", "Oslo", "Norway", "Europe", "Earth", "Solar System");
table.AddRow("Kenny", "55", "Tokyo");
Console.WriteLine(table.ToString());
Console.WriteLine();
}
private static void WriteTableWithStyling(bool headerTextAlignRight, bool rowTextAlignRight, int padding)
{
Console.WriteLine();
Console.WriteLine($"Table with following styling:");
Console.WriteLine($"Header text alignment: {(headerTextAlignRight ? "right" : "left")}");
Console.WriteLine($"Row text alignment: {(rowTextAlignRight ? "right" : "left")}");
Console.WriteLine($"Padding: {padding}");
var table = new Table
{
Padding = padding,
HeaderTextAlignmentRight = headerTextAlignRight,
RowTextAlignmentRight = rowTextAlignRight
};
table.SetHeaders("Name", "Age", "City");
for (int i = 1; i <= 10; i++)
{
if (i % 2 == 0)
table.AddRow($"Name {i}", (i * 8).ToString(), $"City {i}");
else
table.AddRow($"Very Long Name {i}", (i * 8).ToString(), $"City {i}");
}
Console.WriteLine(table.ToString());
Console.WriteLine();
}
private static void WriteTableFluent()
{
Console.WriteLine();
Console.WriteLine("Table fluent:");
var tableString = new Table()
.SetHeaders("Name", "Age", "City")
.AddRow("Alice Cooper", "30", "New York")
.AddRows(
new string[] { "Bob", "25", "Los Angeles" },
new string[] { "Charlie Brown", "47", "Chicago" }
)
.ToTable();
Console.WriteLine(tableString);
Console.WriteLine();
}
}