Is there a way to work with an unspecified number of Generic Type Parameters in a method?
Effectively what I want to do is something like this except for the obvious issue:
private static void FetchChunk(int retries, KeyValuePair<List<dynamic>,Type>[] fetchfields)
{
try
{
foreach (var chunk in fetchfields)
{
var obj = chunk.Key;
obj = DBRepository.GetAll<chunk.Value>().ToList();
}
}
catch
{
//do stuff
}
}
However this fails because instead of Type, I need to use a Generic Type paramater such as T
The problem is however, I don't know how use generics in such a way to achieve what I am trying to achieve. Since I would want a unique generic type parameter for each KeyValuePair in the array.
This on the other hand, absolutely compiles, but doesn't do what I am intending which is each KeyValue pair would have it's own unique Generic Type parameters.
private static void FetchChunk<T>(int retries, KeyValuePair<List<dynamic>, T>[] fetchfields)
{
try
{
foreach (var chunk in fetchfields)
{
var obj = chunk.Key;
obj = DBRepository.GetAll<T>().ToList();
}
}
catch
{
//do stuff
}
The method signature of GetAll is
public static IEnumerable<dynamic> GetAll(Type type, string columnNames = "*")
This doesn't work either:
var type = chunk.Value.GenericTypeArguments[0];
obj = DBRepository.GetAll<type>().ToList();
Is there a way to re-code this method in order to achieve my intentions?