var method = new Func<double, double, double>(Math.Pow).Method; var parameter = Expression.Parameter(typeof(object[])); var args = method.GetParameters() .Select((param, i) => Expression.Convert( Expression.ArrayIndex(parameter, Expression.Constant(i)), param.ParameterType)); var expr = Expression.Lambda<Func<object[], object>>( Expression.Convert(Expression.Call(method, args), typeof(object)), parameter); var invoker = expr.Compile(); var result = invoker(new object[] {Math.PI, 2.0});
No comments:
Post a Comment