-
Notifications
You must be signed in to change notification settings - Fork 4
/
BenchmarkInput.cs
32 lines (28 loc) · 1.02 KB
/
BenchmarkInput.cs
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
using System.Collections;
using System.Globalization;
namespace Benchmarks
{
public class BenchmarkInput<T>
{
public T Value { get; }
public string Name { get; }
public BenchmarkInput(T value, string name = null)
{
Value = value;
Name = name;
}
public override string ToString() => !string.IsNullOrWhiteSpace(Name) ? Name : FormatValue(Value);
private static string FormatValue(object value) =>
value switch
{
null => "∅",
bool b => b ? "true" : "false",
string s => $"\"{s}\"",
char c => $"\'{c}\'",
DateTime dt => dt.ToString("o", CultureInfo.InvariantCulture),
IFormattable @if => @if.ToString(null, CultureInfo.InvariantCulture),
IEnumerable ie => "[" + string.Join(", ", ie.Cast<object>().Select(FormatValue)) + "]",
_ => value.ToString()
};
}
}