using System;
using System.Linq;
using System.Linq.Expressions;
namespace ChangkeTec.Utils
{
public static class LinqBuilder
{
///
/// 默认True条件
///
///
///
public static Expression> True() { return f => true; }
///
/// 默认False条件
///
///
///
public static Expression> False() { return f => false; }
///
/// 拼接 OR 条件
///
///
///
///
///
public static Expression> Or(this Expression> exp, Expression> condition)
{
var inv = Expression.Invoke(condition, exp.Parameters.Cast());
return Expression.Lambda>(Expression.Or(exp.Body, inv), exp.Parameters);
}
///
/// 拼接And条件
///
///
///
///
///
public static Expression> And(this Expression> exp, Expression> condition)
{
var inv = Expression.Invoke(condition, exp.Parameters.Cast());
return Expression.Lambda>(Expression.And(exp.Body, inv), exp.Parameters);
}
}
}