Exemplo n.º 1
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);
        }