/// <summary>
        ///     create and expression ( operator ";" )
        /// </summary>
        /// <param name="visitor"></param>
        /// <param name="context"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Expression <Func <T, bool> > GetAndExpression <T>(
            IRSqlQueryVisitor <Expression <Func <T, bool> > > visitor, RSqlQueryParser.AndContext context)
        {
            if (visitor == null)
            {
                throw new ArgumentNullException(nameof(visitor));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var right = context.constraint()[0].Accept(visitor);

            if (context.constraint().Length == 1)
            {
                return(right);
            }

            for (var i = 1; i < context.constraint().Length; i++)
            {
                var left = context.constraint()[i].Accept(visitor);
                right = Expression.Lambda <Func <T, bool> >(Expression.And(left.Body, right.Body), left.Parameters);
            }

            return(right);
        }
Example #2
0
        public void ShouldBeGetAndExpressionThrowArgumentNullExceptionTest()
        {
            // visitor = null
            var context = new RSqlQueryParser.AndContext(null, 0);

            this.Invoking(a => RSqlQueryExpressionHelper.GetAndExpression <Customer>(null, context))
            .Should().Throw <ArgumentNullException>();

            var visitor = new RSqlDefaultQueryVisitor <Customer>(JsonNamingPolicy.CamelCase);

            // context = null
            this.Invoking(a => RSqlQueryExpressionHelper.GetAndExpression(visitor, null))
            .Should().Throw <ArgumentNullException>();
        }
Example #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="RSqlQueryParser.and"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitAnd([NotNull] RSqlQueryParser.AndContext context)
 {
     return(VisitChildren(context));
 }
Example #4
0
 /// <summary>
 ///     visit a and expression
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public override Expression <Func <T, bool> > VisitAnd(RSqlQueryParser.AndContext context)
 {
     return(RSqlQueryExpressionHelper.GetAndExpression(this, context));
 }
 /// <summary>
 /// Enter a parse tree produced by <see cref="RSqlQueryParser.and"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void EnterAnd([NotNull] RSqlQueryParser.AndContext context)
 {
 }