Expression拼接
程序员文章站
2022-09-26 21:57:04
public static class ExpressionHelp { /// /// Lambda表达式拼接 /// /// ///
public static class expressionhelp { /// <summary> /// lambda表达式拼接 /// </summary> /// <typeparam name="t"></typeparam> /// <param name="first"></param> /// <param name="second"></param> /// <param name="merge"></param> /// <returns></returns> public static expression<t> compose<t>(this expression<t> first, expression<t> second, func<expression, expression, expression> merge) { var map = first.parameters.select((f, i) => new { f, s = second.parameters[i] }).todictionary(p => p.s, p => p.f); var secondbody = parameterrebinder.replaceparameters(map, second.body); return expression.lambda<t>(merge(first.body, secondbody), first.parameters); } /// <summary> /// and扩展 /// </summary> /// <typeparam name="t"></typeparam> /// <param name="first"></param> /// <param name="second"></param> /// <returns></returns> public static expression<func<t1, t2, bool>> and<t1, t2>(this expression<func<t1, t2, bool>> first, expression<func<t1, t2, bool>> second) { return first.compose(second, expression.and); } public static expression<func<t, bool>> and<t>(this expression<func<t, bool>> first, expression<func<t, bool>> second) { return first.compose(second, expression.and); } /// <summary> /// or扩展 /// </summary> /// <typeparam name="t"></typeparam> /// <param name="first"></param> /// <param name="second"></param> /// <returns></returns> public static expression<func<t1, t2, bool>> or<t1, t2>(this expression<func<t1, t2, bool>> first, expression<func<t1, t2, bool>> second) { return first.compose(second, expression.or); } public static expression<func<t, bool>> or<t>(this expression<func<t, bool>> first, expression<func<t, bool>> second) { return first.compose(second, expression.or); } }
上一篇: 今年断更 LG G系列可能被砍:G9 ThinQ或不会发布
下一篇: Java四种多线程的使用详解
推荐阅读
-
C++ lambda expression
-
Python 使用PIL numpy 实现拼接图片的示例
-
js最实用string(字符串)类型的使用及截取与拼接详解
-
C#条件拼接Expression<Func<T, bool>>的使用
-
优酷IDO怎么用?优酷IDO拼接视频的详细教程
-
PS做景深拼接制造出清晰效果通过使用对焦堆叠技术实现
-
浅谈jquery拼接字符串效率比较高的方法
-
C#拼接SQL语句 用ROW_NUMBER实现的高效分页排序
-
为什么 Java 8 中不需要 StringBuilder 拼接字符串
-
oracle—SQL技巧之(二)WMSYS.WM_CONCAT函数实现多行记录用逗号拼接在一起