-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayHelper.cs
More file actions
37 lines (32 loc) · 1005 Bytes
/
Copy pathDisplayHelper.cs
File metadata and controls
37 lines (32 loc) · 1005 Bytes
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
using System.Collections;
using System.Text;
namespace CodingRange
{
public static class DisplayHelper
{
private static string CollectionToString(IEnumerable array, bool simplify)
{
StringBuilder stringBuilder = new(simplify
? string.Empty
: "{ ");
foreach (var x in array)
{
stringBuilder.Append($"{ForDisplay(x, false)}, ");
}
stringBuilder.Remove(stringBuilder.Length - 2, 2);
var end = simplify
? string.Empty
: " }";
return $"{stringBuilder}{end}";
}
public static string ForDisplay(object x, bool simplify) => x switch
{
null => "null",
string s => $"\"{s}\"",
IEnumerable ie => CollectionToString(ie, simplify),
char c => $"'{c}'",
bool b => b.ToString().ToLower(),
_ => x.ToString()
};
}
}