Skip to content

Commit 8aa83d5

Browse files
Merge pull request #82 from ipz234/main
Lack of Encapsulation
2 parents e928d39 + c528cfc commit 8aa83d5

1 file changed

Lines changed: 51 additions & 73 deletions

File tree

src/ConsoleTables.Sample/Program.cs

Lines changed: 51 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,72 @@
22
using System.Collections.Generic;
33
using System.Linq;
44

5-
namespace ConsoleTables.Sample;
6-
7-
static class Program
5+
namespace ConsoleTables.Sample
86
{
9-
static void TestDictionaryTable()
7+
static class Program
108
{
11-
Dictionary<string, Dictionary<string, object>> data = new Dictionary<string, Dictionary<string, object>>()
9+
static void Main(string[] args)
1210
{
13-
{"A", new Dictionary<string, object>()
14-
{
15-
{ "A", true },
16-
{ "B", false },
17-
{ "C", true },
18-
}},
19-
{"B", new Dictionary<string, object>()
20-
{
21-
{ "A", false },
22-
{ "B", true },
23-
{ "C", false },
24-
}},
25-
{"C", new Dictionary<string, object>()
26-
{
27-
{ "A", false },
28-
{ "B", false },
29-
{ "C", true },
30-
}}
31-
};
32-
var table = ConsoleTable.FromDictionary(data);
11+
TestDictionaryTable();
12+
SetupAndWriteTables();
13+
ConfigureAlignment();
14+
WriteTableWithoutCount();
3315

34-
Console.WriteLine(table.ToString());
35-
}
36-
37-
static void Main(string[] args)
38-
{
39-
TestDictionaryTable();
40-
var table = new ConsoleTable("one", "two", "three");
41-
table.AddRow(1, 2, 3)
42-
.AddRow("this line should be longer 哈哈哈哈", "yes it is", "oh");
16+
Console.ReadKey();
17+
}
4318

44-
Console.WriteLine("\nFORMAT: Default:\n");
45-
table.Write();
46-
47-
Console.WriteLine("\nFORMAT: MarkDown:\n");
48-
table.Write(Format.MarkDown);
49-
50-
Console.WriteLine("\nFORMAT: Alternative:\n");
51-
table.Write(Format.Alternative);
52-
Console.WriteLine();
53-
54-
Console.WriteLine("\nFORMAT: Minimal:\n");
55-
table.Write(Format.Minimal);
56-
Console.WriteLine();
57-
58-
table = new ConsoleTable("I've", "got", "nothing");
59-
table.Write();
60-
Console.WriteLine();
19+
static void TestDictionaryTable()
20+
{
21+
var data = new List<TableData>
22+
{
23+
new TableData("A", new Dictionary<string, object> { { "A", true }, { "B", false }, { "C", true } }),
24+
new TableData("B", new Dictionary<string, object> { { "A", false }, { "B", true }, { "C", false } }),
25+
new TableData("C", new Dictionary<string, object> { { "A", false }, { "B", false }, { "C", true } })
26+
};
6127

62-
var rows = Enumerable.Repeat(new Something(), 10);
28+
var dictionary = data.ToDictionary(d => d.Key, d => d.Values);
29+
var table = ConsoleTable.FromDictionary(dictionary);
30+
Console.WriteLine(table.ToString());
31+
}
6332

64-
ConsoleTable.From(rows).Write();
33+
static void SetupAndWriteTables()
34+
{
35+
var table = new ConsoleTable("one", "two", "three");
36+
table.AddRow(1, 2, 3)
37+
.AddRow("this line should be longer 哈哈哈哈", "yes it is", "oh");
6538

66-
rows = Enumerable.Repeat(new Something(), 0);
67-
ConsoleTable.From(rows).Write();
39+
table.Write();
40+
}
6841

69-
Console.WriteLine("\nNumberAlignment = Alignment.Right\n");
70-
rows = Enumerable.Repeat(new Something(), 2);
71-
ConsoleTable
72-
.From(rows)
73-
.Configure(o => o.NumberAlignment = Alignment.Right)
74-
.Write();
42+
static void ConfigureAlignment()
43+
{
44+
var rows = Enumerable.Repeat(new Something(), 2);
45+
ConsoleTable.From(rows)
46+
.Configure(o => o.NumberAlignment = Alignment.Right)
47+
.Write();
48+
}
7549

76-
var noCount =
77-
new ConsoleTable(new ConsoleTableOptions
50+
static void WriteTableWithoutCount()
51+
{
52+
var noCount = new ConsoleTable(new ConsoleTableOptions
7853
{
7954
Columns = new[] { "one", "two", "three" },
8055
EnableCount = false
8156
});
8257

83-
noCount.AddRow(1, 2, 3).Write();
58+
noCount.AddRow(1, 2, 3).Write();
59+
}
60+
}
61+
62+
public class Something
63+
{
64+
public string Id { get; } = Guid.NewGuid().ToString("N");
65+
public string Name { get; private set; } = "Khalid Abuhkameh";
66+
public DateTime Date { get; }
8467

85-
Console.ReadKey();
68+
public Something()
69+
{
70+
Date = DateTime.UtcNow;
71+
}
8672
}
8773
}
88-
89-
public class Something
90-
{
91-
public string Id { get; set; } = Guid.NewGuid().ToString("N");
92-
public string Name { get; set; } = "Khalid Abuhkameh";
93-
public DateTime Date { get; set; } = DateTime.Now;
94-
public int NumberOfChildren { get; set; }
95-
}

0 commit comments

Comments
 (0)