protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.IsIfMethod())
            {
                Expression predicate = m.Arguments[1].RemoveCastToObject();
                Expression result = new MemberAccessNullPropagateVisitor().Rewrite(predicate);

                BinaryExpression conditionPredicate = Expression.Equal(result, Expression.Constant(result.Type.GetDefaultValue(), result.Type));
                return Expression.Condition(conditionPredicate, Expression.Constant(m.Arguments[0].Type.GetDefaultValue(), m.Arguments[0].Type), m.Arguments[0]);
            }
            return base.VisitMethodCall(m);
        }
Exemple #2
0
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.IsIfMethod())
            {
                Expression predicate = m.Arguments[1].RemoveCastToObject();
                Expression result    = new MemberAccessNullPropagateVisitor().Rewrite(predicate);

                BinaryExpression conditionPredicate = Expression.Equal(result, Expression.Constant(result.Type.GetDefaultValue(), result.Type));
                return(Expression.Condition(conditionPredicate, Expression.Constant(m.Arguments[0].Type.GetDefaultValue(), m.Arguments[0].Type), m.Arguments[0]));
            }
            return(base.VisitMethodCall(m));
        }
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.IsSelectHtmlMethod())
            {
                Expression iterator = m.Arguments[0];
                Expression nullPropagatingIterator = new MemberAccessNullPropagateVisitor().Rewrite(iterator);

                PropertyPath iteratorPath = CreatePropertyPath(iterator);

                Expression iteratorRoot = GetIteratorRoot(iterator);

                Expression rootInstanceParameter = iteratorRoot ?? Expression.Constant(null, typeof(object));
                ConstantExpression propertyPathParameter = Expression.Constant(iteratorPath);

                MethodCallExpression callExpression = Expression.Call(m.Method,
                                                                      nullPropagatingIterator,
                                                                      rootInstanceParameter,
                                                                      propertyPathParameter,
                                                                      Visit(m.Arguments[3]));
                return callExpression;
            }
            return base.VisitMethodCall(m);
        }
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.IsSelectHtmlMethod())
            {
                Expression iterator = m.Arguments[0];
                Expression nullPropagatingIterator = new MemberAccessNullPropagateVisitor().Rewrite(iterator);

                PropertyPath iteratorPath = CreatePropertyPath(iterator);

                Expression iteratorRoot = GetIteratorRoot(iterator);

                Expression         rootInstanceParameter = iteratorRoot ?? Expression.Constant(null, typeof(object));
                ConstantExpression propertyPathParameter = Expression.Constant(iteratorPath);

                MethodCallExpression callExpression = Expression.Call(m.Method,
                                                                      nullPropagatingIterator,
                                                                      rootInstanceParameter,
                                                                      propertyPathParameter,
                                                                      Visit(m.Arguments[3]));
                return(callExpression);
            }
            return(base.VisitMethodCall(m));
        }