-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchTypes.tt
61 lines (57 loc) · 1.18 KB
/
SwitchTypes.tt
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
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
using System;
using System.Collections.Generic;
using StaticTypedDictionaryBenchmark;
using System.Buffers;
// Autogenerated
// ReSharper disable BuiltInTypeReferenceStyle
namespace StaticTypedDictionaryBenchmark
{
<# for(int i = 1;i<=1000;i++) {
string name = "Request"+i;
#>
public sealed class <#= name #> : IRequest
{
public int Value => <#=i#>;
}
<# } #>
public static class SwitchHelper
{
public static int Switch<T>(T t) where T : class
{
switch(t)
{
<# for(int i = 1;i<=1000;i++) {
string name = "Request"+i;
#>
case <#= name #> r<#=i#>:
{
return r<#=i#>.Value;
}
<# } #>
}
return 0;
}
}
public static class StaticSwitchHelper
{
static StaticSwitchHelper()
{
<# for(int i = 1;i<=1000;i++) {
string name = "Request"+i;
#>
_ = TypeIndex<IRequest>.Add<<#= name #>>(new <#= name #>());
<# } #>
}
public static int Switch<T>(T t) where T : class
{
var r = TypeIndex<IRequest>.Get<T>();
return r?.Value ?? 0;
}
}
}