/// <summary> /// Generates a function that performs all type conversions, /// assuming that the types are correct. Called once per /// registered function. /// </summary> private static Func <Value[], Value> GenerateCall(Type[] parameters, MethodInfo meta) { ParameterExpression vs = Expression.Parameter(typeof(Value[]), "vs"); Expression[] casts = new Expression[parameters.Length]; // Convert types after conversion rules, if necessary. for (int i = 0; i < casts.Length; ++i) { Expression v = Expression.ArrayIndex(vs, Expression.Constant(i, typeof(int))); if (parameters[i].BaseType == TypeConversion.VALUE_T) { casts[i] = Expression.Convert(v, parameters[i]); } else { casts[i] = Expression.Call(v, TypeConversion.FuncalcConversion(parameters[i])); } } Expression call = Expression.Call(meta, casts); return(Expression.Lambda(call, vs).Compile() as Func <Value[], Value>); }