using System; using System.Linq.Expressions; namespace SqlSugar { public class Expressionable where T : class, new() { private Expression> _exp = null; public Expressionable And(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable AndIF(bool isAnd, Expression> exp) { if (isAnd) And(exp); return this; } public Expressionable Or(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable OrIF(bool isOr, Expression> exp) { if (isOr) Or(exp); return this; } public Expression> ToExpression() { if (_exp == null) _exp = it => true; return _exp; } } public class Expressionable where T : class, new() where T2 : class, new() { private Expression> _exp = null; public Expressionable And(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable AndIF(bool isAnd, Expression> exp) { if (isAnd) And(exp); return this; } public Expressionable Or(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable OrIF(bool isOr, Expression> exp) { if (isOr) Or(exp); return this; } public Expression> ToExpression() { if (_exp == null) _exp = (it, t2) => true; return _exp; } } public class Expressionable where T : class, new() where T2 : class, new() where T3 : class, new() { private Expression> _exp = null; public Expressionable And(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable AndIF(bool isAnd, Expression> exp) { if (isAnd) And(exp); return this; } public Expressionable Or(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable OrIF(bool isOr, Expression> exp) { if (isOr) Or(exp); return this; } public Expression> ToExpression() { if (_exp == null) _exp = (it, t2, t3) => true; return _exp; } } public class Expressionable where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() { private Expression> _exp = null; public Expressionable And(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable AndIF(bool isAnd, Expression> exp) { if (isAnd) And(exp); return this; } public Expressionable Or(Expression> exp) { _exp = _exp == null ? exp : Expression.Lambda>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters); return this; } public Expressionable OrIF(bool isOr, Expression> exp) { if (isOr) Or(exp); return this; } public Expression> ToExpression() { if (_exp == null) _exp = (it, t2, t3, t4) => true; return _exp; } } public class Expressionable { public static Expressionable Create() where T : class, new() { return new Expressionable(); } public static Expressionable Create() where T : class, new() where T2 : class, new() { return new Expressionable(); } public static Expressionable Create() where T : class, new() where T2 : class, new() where T3 : class, new() { return new Expressionable(); } public static Expressionable Create() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() { return new Expressionable(); } } }