At the moment I'm doing this (//edit: which is totally stupid as there's array which consequentily numbers its items in the same way that I did my Dictionary yesterday):
Dictionary<int, Type> genericMap = new Dictionary<int, Type>
{
{ 0, typeof(Action) },
{ 1, typeof(Action<>) },
{ 2, typeof(Action<,>) },
{ 3, typeof(Action<,,>) },
{ 4, typeof(Action<,,,>) },
{ 5, typeof(Action<,,,,>) },
{ 6, typeof(Action<,,,,,>) },
{ 7, typeof(Action<,,,,,,>) },
{ 8, typeof(Action<,,,,,,,>) },
};
And somewhere else...
var parms = meth.GetParameters();
dType = genericMap[parms.Length].MakeGenericType(parms.Select(p => p.ParameterType).ToArray());
where meth is a MethodInfo.
Is there a more elegant way to do that? Or do I have to define a map like this to get the correct Action<> type dynamically that corresponds to the parameter count?