Utils
using System;
using System.Reflection;
namespace Stashbox.Expressions.Compile
{
internal static class Utils
{
public static readonly Type ClosureType = typeof(Closure);
public static readonly Type ObjectArrayType = typeof(object[]);
public static Type MapDelegateType(Type[] paramTypes)
{
switch (paramTypes.Length) {
case 1:
return typeof(Func<>).MakeGenericType(paramTypes);
case 2:
return typeof(Func<, >).MakeGenericType(paramTypes);
case 3:
return typeof(Func<, , >).MakeGenericType(paramTypes);
case 4:
return typeof(Func<, , , >).MakeGenericType(paramTypes);
case 5:
return typeof(Func<, , , , >).MakeGenericType(paramTypes);
case 6:
return typeof(Func<, , , , , >).MakeGenericType(paramTypes);
case 7:
return typeof(Func<, , , , , , >).MakeGenericType(paramTypes);
case 8:
return typeof(Func<, , , , , , , >).MakeGenericType(paramTypes);
default:
throw new NotSupportedException($"""{paramTypes.Length}""");
}
}
internal static MethodInfo GetPartialApplicationMethodInfo(Type[] types)
{
return PartialApplication.Methods[types.Length - 2].MakeGenericMethod(types);
}
}
}