Exemplo n.º 1
0
        /// <summary>Or操作</summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        public WhereExpression Or(Expression exp)
        {
            if (exp != null)
            {
                Expressions.Add(new ExpItem(false, exp));
            }

            return this;
        }
Exemplo n.º 2
0
        /// <summary>And操作</summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        public WhereExpression And(Expression exp)
        {
            if (exp != null)
            {
                // 如果前面有Or,则整体推入下一层
                if (Expressions.Any(e => !e.IsAnd))
                {
                    var where = new WhereExpression();
                    where.Expressions.AddRange(Expressions);

                    Expressions.Clear();
                    Expressions.Add(new ExpItem(true, where));
                }

                Expressions.Add(new ExpItem(true, exp));
            }

            return this;
        }
Exemplo n.º 3
0
        static WhereExpression And(Expression exp, Expression value)
        {
            // 如果exp为空,主要考虑右边
            if (exp == null) CreateWhere(value);

            // 左边构造条件表达式,自己是也好,新建立也好
            var where = CreateWhere(exp);
            if (value == null) return where;

            // 如果右边为空,创建的表达式将会失败,直接返回左边
            return where.And(value);
        }
Exemplo n.º 4
0
        static WhereExpression CreateWhere(Expression value)
        {
            if (value == null) return new WhereExpression();
            if (value is WhereExpression) return (value as WhereExpression);

            return new WhereExpression(value);
        }
Exemplo n.º 5
0
 /// <summary>把普通表达式包装为条件表达式表达式</summary>
 /// <param name="exp"></param>
 public WhereExpression(Expression exp) { And(exp); }
Exemplo n.º 6
0
 public ExpItem(Boolean isAnd, Expression exp)
 {
     IsAnd = isAnd;
     Exp = exp;
 }
Exemplo n.º 7
0
 /// <summary>有条件Or操作</summary>
 /// <param name="condition"></param>
 /// <param name="exp"></param>
 /// <returns></returns>
 public WhereExpression OrIf(Boolean condition, Expression exp) { return condition ? Or(exp) : this; }
Exemplo n.º 8
0
 /// <summary>有条件And操作</summary>
 /// <param name="condition"></param>
 /// <param name="exp"></param>
 /// <returns></returns>
 public WhereExpression AndIf(Boolean condition, Expression exp) { return condition ? And(exp) : this; }