Ejemplo n.º 1
0
        public static Expression[] GetMethodParamSettersFromArray(this MethodInfo methodInfo, ParameterExpression arrayParams)
        {
            Expression[] paramSetters =
                methodInfo.GetParameters().Select((param, idx) => Expression.Convert(arrayParams.CreateArrayCellAccessExpression(idx), param.ParameterType)).ToArray();

            return(paramSetters);
        }
Ejemplo n.º 2
0
        // basically for method MyMethod(int i, string str) return a body of the method that would pass
        // the same params as an object array
        // MyMethodCall(object[] inputParams)
        // {
        //     MyMethod((int)inputParams[0], (string) inputParams[1]);
        // }
        public static MethodCallExpression GetMethodCallFromParamArray
        (
            this MethodInfo methodInfo,
            ParameterExpression inputParams,
            object obj = null)
        {
            Expression[] paramSetters =
                methodInfo.GetParameters()
                .Select
                (
                    (param, idx) =>
                    Expression.Convert
                    (
                        inputParams.CreateArrayCellAccessExpression(idx),
                        param.ParameterType)).ToArray();
            Expression instanceExpression = null;

            if (obj != null)
            {
                instanceExpression = Expression.Constant(obj);
            }

            MethodCallExpression methodCallExpr = Expression.Call(instanceExpression, methodInfo, paramSetters);

            return(methodCallExpr);
        }
Ejemplo n.º 3
0
        public static Expression CreateAssignArrayCellExpression
        (
            this ParameterExpression arrayParameterExpression, // e.g. created by Expression.Parameter(typeof(object[]), "inputParams");
            int cellIdx,
            Expression exprToAssign)
        {
            var assignArrayCell =
                Expression.Assign
                (
                    arrayParameterExpression.CreateArrayCellAccessExpression(cellIdx),
                    exprToAssign);

            return(assignArrayCell);
        }