PowerAssert.Infrastructure.ExpressionParser.DynamicInvoke C# (CSharp) Method

DynamicInvoke() private method

private DynamicInvoke ( Expression e ) : object
e System.Linq.Expressions.Expression
return object
        internal object DynamicInvoke(Expression e)
        {
            if (TextOnly)
                return null;
            return Expression.Lambda(e, _parameters).Compile().DynamicInvoke(_parameterValues);
        }
    }

Usage Example

        static bool CheckArgument(ExpressionParser parser, MethodCallExpression methE, bool left, out string hint)
        {
            int ix1 = left ? 0 : 1;
            int ix2 = left ? 1 : 0;

            if (typeof (Delegate).IsAssignableFrom(methE.Arguments[ix1].Type))
            {
                object leftR;
                try
                {
                    leftR = parser.DynamicInvoke(Expression.Invoke(methE.Arguments[ix1]));
                }
                catch (InvalidOperationException) // delegate needs arguments
                {
                    hint = null;
                    return false;
                }

                if (Equals(leftR, parser.DynamicInvoke(methE.Arguments[ix2])))
                {
                    hint = string.Format(", but would have been True if you had invoked '{0}'",
                        NodeFormatter.PrettyPrint(parser.Parse(methE.Arguments[ix1])));
                    return true;
                }
            }

            hint = null;
            return false;
        }
All Usage Examples Of PowerAssert.Infrastructure.ExpressionParser::DynamicInvoke