I have a Type[] array and I want to get the Func type where T1, T2 etc… correspond to the types in the array. The array is not fixed in size but assume a type is available in the runtime (16 in .NET 4, 4 in .NET 3.5).
In .NET 4, I can do this and it works:
Type GetFuncType(Type typeRet, Type[] types)
{
return Type.GetType(string.Format("System.Func`{0}", types.Length + 1))
.MakeGenericType(types.Concat(new Type[] { typeRet } ).ToArray())
}
In .NET 3.5 however, the Type.GetType for the open generic type fails, returning NULL.
Is there a way I make this work in .NET 3.5? My only thought atm is to build up a string for the close generic type.
The preferred way of doing this is to use
Expression.GetFuncType(Type[])andExpression.GetActionType(Type[]). In the case of func, the lastTypeis the return, so: