/// <summary> /// Combines two given expressions by using the AND semantics. /// </summary> /// <typeparam name="T">The type of the object.</typeparam> /// <param name="first">The first part of the expression.</param> /// <param name="second">The second part of the expression.</param> /// <returns>The combined expression.</returns> public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second) { return first.Compose(second, Expression.AndAlso); } /// <summary> /// Combines two given expressions by using the OR semantics. /// </summary> /// <typeparam name="T">The type of the object.</typeparam> /// <param name="first">The first part of the expression.</param> /// <param name="second">The second part of the expression.</param> /// <returns>The combined expression.</returns> public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second) { return first.Compose(second, Expression.OrElse); } public static Expression<Func<T, bool>> AndForOr<T>(this Expression<Func<T, bool>> lambda, Expression<Func<T, bool>> first, Expression<Func<T, bool>> second) { return null; }
如上代码,我想拼接and 和or表达式,求解
AndForOr 这个方法实现了什么功能?
whereExpression.AndForOr(exp1,exp2);
类似于这种
@未找到对象: 不明白,你是想要达到A && B还是A || B还是其它逻辑?
然后呢?
AndForOr 这个方法就是想写拼接,写不出来
@未找到对象: 参考LinqKit和Predicate.cs的源码。http://www.albahari.com/nutshell/linqkit.aspx