ExpressionTypeNotInvocable() static private method

ArgumentException with message like "Expression of type '{0}' cannot be invoked"
static private ExpressionTypeNotInvocable ( object p0, string paramName ) : Exception
p0 object
paramName string
return System.Exception
        //CONFORMING
        public static InvocationExpression Invoke(Expression expression, IEnumerable <Expression> arguments)
        {
            RequiresCanRead(expression, "expression");

            Type delegateType = expression.Type;

            if (delegateType == typeof(Delegate))
            {
                throw Error.ExpressionTypeNotInvocable(delegateType);
            }
            else if (!typeof(Delegate).IsAssignableFrom(expression.Type))
            {
                Type exprType = TypeUtils.FindGenericType(typeof(Expression <>), expression.Type);
                if (exprType == null)
                {
                    throw Error.ExpressionTypeNotInvocable(expression.Type);
                }
                delegateType = exprType.GetGenericArguments()[0];
            }

            var mi   = delegateType.GetMethod("Invoke");
            var args = arguments.ToReadOnly();

            ValidateArgumentTypes(mi, ExpressionType.Invoke, ref args);
            return(new InvocationExpression(expression, args, mi.ReturnType));
        }
示例#2
0
        /// <summary>
        /// Gets the delegate's Invoke method; used by InvocationExpression.
        /// </summary>
        /// <param name="expression">The expression to be invoked.</param>
        internal static MethodInfo GetInvokeMethod(Expression expression)
        {
            Type delegateType = expression.Type;

            if (!expression.Type.IsSubclassOf(typeof(MulticastDelegate)))
            {
                Type exprType = TypeUtils.FindGenericType(typeof(Expression <>), expression.Type);
                if (exprType == null)
                {
                    throw Error.ExpressionTypeNotInvocable(expression.Type, nameof(expression));
                }
                delegateType = exprType.GetGenericArguments()[0];
            }

            return(delegateType.GetMethod("Invoke"));
        }