-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlockData.cs
More file actions
82 lines (69 loc) · 2.26 KB
/
BlockData.cs
File metadata and controls
82 lines (69 loc) · 2.26 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
using System;
using System.Collections.Generic;
namespace IntelliTect.TestTools.TestFramework;
public interface IBlockData
{
public List<KeyValuePair<Type, object?>> Data { get; }
}
public class BlockData<T1, T2>(T1 data1, T2 data2) : IBlockData
{
static BlockData()
{
ValidateData.ValidateUniqueTypes(typeof(T1), typeof(T2));
}
public T1 Data1 => data1;
public T2 Data2 => data2;
List<KeyValuePair<Type, object?>> IBlockData.Data { get; } =
[
new KeyValuePair<Type, object?>(typeof(T1), data1),
new KeyValuePair<Type, object?>(typeof(T2), data2)
];
}
public class BlockData<T1, T2, T3>(T1 data1, T2 data2, T3 data3) : IBlockData
{
static BlockData()
{
ValidateData.ValidateUniqueTypes(typeof(T1), typeof(T2), typeof(T3));
}
public T1 Data1 => data1;
public T2 Data2 => data2;
public T3 Data3 => data3;
List<KeyValuePair<Type, object?>> IBlockData.Data { get; } =
[
new KeyValuePair<Type, object?>(typeof(T1), data1),
new KeyValuePair<Type, object?>(typeof(T2), data2),
new KeyValuePair<Type, object?>(typeof(T3), data3)
];
}
public class BlockData<T1, T2, T3, T4>(T1 data1, T2 data2, T3 data3, T4 data4) : IBlockData
{
static BlockData()
{
ValidateData.ValidateUniqueTypes(typeof(T1), typeof(T2), typeof(T3), typeof(T4));
}
public T1 Data1 => data1;
public T2 Data2 => data2;
public T3 Data3 => data3;
public T4 Data4 => data4;
List<KeyValuePair<Type, object?>> IBlockData.Data { get; } =
[
new KeyValuePair<Type, object?>(typeof(T1), data1),
new KeyValuePair<Type, object?>(typeof(T2), data2),
new KeyValuePair<Type, object?>(typeof(T3), data3),
new KeyValuePair<Type, object?>(typeof(T4), data4)
];
}
internal static class ValidateData
{
internal static void ValidateUniqueTypes(params Type[] types)
{
HashSet<Type> seenTypes = [];
foreach(Type type in types)
{
if (!seenTypes.Add(type))
{
throw new InvalidOperationException($"Duplicate type found: {type.Name} appears multiple times. BlockData must use different types to avoid unexpected behavior by the TestCase DI Container.");
}
}
}
}