Ejemplo n.º 1
0
        private static LambdaExpression GetExpression(IQueryable source, Func <dynamic, dynamic> expressionBuilder)
        {
            ParameterExpression      parameterExpression = Expression.Parameter(GetElementType(source), expressionBuilder.Method.GetParameters()[0].Name);
            DynamicExpressionBuilder dynamicExpression   = expressionBuilder(new DynamicExpressionBuilder(parameterExpression));
            Expression body = dynamicExpression.Expression;

            return(Expression.Lambda(body, parameterExpression));
        }
Ejemplo n.º 2
0
        public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
        {
            if (binder.Operation == ExpressionType.IsFalse || binder.Operation == ExpressionType.IsTrue)
            {
                result = false;
                return(true);
            }

            result = new DynamicExpressionBuilder(Expression.MakeUnary(binder.Operation, Expression, binder.ReturnType));
            return(true);
        }
Ejemplo n.º 3
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            // TODO: As a first attempt we can use the member names of the parameters to try and resolve the overload

            MethodInfo methodInfo = null;

            if (args.Any(a => a == null))
            {
                methodInfo = Expression.Type.GetMethod(binder.Name);
            }
            else
            {
                var types = args.Select(arg => arg.GetType()).ToArray();
                methodInfo = Expression.Type.GetMethod(binder.Name, types);
            }

            if (methodInfo != null)
            {
                var expression = Expression.Call(Expression, methodInfo, args.Select(Expression.Constant));
                result = new DynamicExpressionBuilder(expression);
                return(true);
            }
            return(base.TryInvokeMember(binder, args, out result));
        }
Ejemplo n.º 4
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     result = new DynamicExpressionBuilder(Expression.Property(Expression, binder.Name));
     return(true);
 }