Ejemplo n.º 1
0
        /// <summary>
        /// ConditionalExpression visit method
        /// </summary>
        /// <param name="c">The ConditionalExpression expression to visit</param>
        /// <returns>
        /// The visited ConditionalExpression expression
        /// </returns>
        internal override Expression VisitConditional(ConditionalExpression c)
        {
            var nullEqualConditionalMatch = ExpressionUtil.MatchNullEqualConditional(c);

            if (nullEqualConditionalMatch != null &&
                nullEqualConditionalMatch.ComparisonOperand.Type == typeof(String))
            {
                if (((MemberExpression)nullEqualConditionalMatch.ComparisonOperand).Member.Name == ((MemberExpression)((MethodCallExpression)((UnaryExpression)nullEqualConditionalMatch.IfNotNull).Operand).Object).Member.Name)
                {
                    return(ExpressionUtil.RemoveConversionsAndTypeAs(nullEqualConditionalMatch.IfNotNull));
                }
            }

            return(base.VisitConditional(c));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Optimizes the filter contains expressions.
        /// </summary>
        /// <param name="expr">The expr.</param>
        /// <returns></returns>
        private static Expression OptimizeFilterContainsExpressions(Expression expr)
        {
            var nullEqualConditionalMatch = ExpressionUtil.MatchNullEqualConditional(expr);

            if (nullEqualConditionalMatch != null &&
                nullEqualConditionalMatch.ComparisonOperand.Type == typeof(String))
            {
                if (((MemberExpression)nullEqualConditionalMatch.ComparisonOperand).Member.Name == ((MemberExpression)((MethodCallExpression)((UnaryExpression)nullEqualConditionalMatch.IfNotNull).Operand).Object).Member.Name)
                {
                    return(ExpressionUtil.RemoveConversionsAndTypeAs(nullEqualConditionalMatch.IfNotNull));
                }
            }

            return(expr);
        }