Ejemplo n.º 1
0
        protected override FilterExpression Transform(FilterCallExpression lx)
        {
            if (!Operators.WildcardComparators.Contains(lx.OperatorName) || lx.Operands.Length != 2)
            {
                return(base.Transform(lx));
            }

            var lhsIs = FilterExpressionWildcardSearch.FindElementAtWildcard(lx.Operands[0]);
            var rhsIs = FilterExpressionWildcardSearch.FindElementAtWildcard(lx.Operands[1]);

            if (lhsIs != null && rhsIs != null || lhsIs == null && rhsIs == null)
            {
                return(base.Transform(lx)); // N/A, or invalid
            }
            var wcpath    = lhsIs != null ? lx.Operands[0] : lx.Operands[1];
            var comparand = lhsIs != null ? lx.Operands[1] : lx.Operands[0];
            var elmat     = lhsIs ?? rhsIs;

            var parm            = new FilterParameterExpression("p" + _nextParameter++);
            var nestedComparand = FilterExpressionNodeReplacer.Replace(wcpath, elmat, parm);

            var coll = elmat.Operands[0];
            var wc   = ((FilterWildcardExpression)elmat.Operands[1]).Wildcard;

            var comparisonArgs = lhsIs != null ? new[] { nestedComparand, comparand } : new[] { comparand, nestedComparand };
            var body           = new FilterCallExpression(lx.OperatorName, comparisonArgs);
            var lambda         = new FilterLambdaExpression(new[] { parm }, body);

            var op   = Operators.ToRuntimeWildcardOperator(wc);
            var call = new FilterCallExpression(op, new[] { coll, lambda });

            return(Transform(call));
        }
        public static FilterCallExpression FindElementAtWildcard(FilterExpression fx)
        {
            var search = new FilterExpressionWildcardSearch();

            return(search.Transform(fx));
        }