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

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var right = context.and()[0].Accept(visitor);

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

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

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

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

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

            // context = null
            this.Invoking(a => RSqlQueryExpressionHelper.GetOrExpression(visitor, null))
            .Should().Throw <ArgumentNullException>();
        }
Example #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="RSqlQueryParser.or"/>.
 /// <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 VisitOr([NotNull] RSqlQueryParser.OrContext context)
 {
     return(VisitChildren(context));
 }
Example #4
0
 /// <summary>
 ///     visit a or expression
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public override Expression <Func <T, bool> > VisitOr(RSqlQueryParser.OrContext context)
 {
     return(RSqlQueryExpressionHelper.GetOrExpression(this, context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="RSqlQueryParser.or"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitOr([NotNull] RSqlQueryParser.OrContext context)
 {
 }