What I want is simple:
public class Collection<T1,...TN> where T1...TN : SomeClass {
public static Type[] types = {typeof(T1)...typeof(TN)}
}
How one can generate such base classes for Ns from 1 to N (say default is 40)?
I ended up with something like this .tt template:
<#@ template hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
using System;
using System.Collections.Generic;
using System.Text;
namespace Services
{
public interface ICollections {
public Type[] Types {get;}
}
<#
int top = 10;
for (int i = 0; i<=top; i++)
{ #>
public class Collections< <# for (int j = 0; j<=i; j++) {#> T<#=j#> <#= (j<i )?(","):(" ") #> <# }#> > : ICollections <# for (int j = 0; j<=i; j++) {#>
where T<#=j#> : SomeClass <# }#>
{
public Type[] Types => new[] { <# for (int j = 0; j<=i; j++) {#> typeof(T<#=j#>) <#= (j<i )?(","):(" ") #> <# }#>};
}
<# } #>
}