zoukankan      html  css  js  c++  java
  • Expression拼接

    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);
            }
    
        }
  • 相关阅读:
    dedecms织梦自定义表单发送到邮箱-用163邮箱发送邮件
    DedeCMS实现自定义表单提交后发送指定QQ邮箱法
    什么是授权码,它又是如何设置?
    telnet配置和telnet用法
    linux利用sendmail发送邮件的方法
    SSH会话连接超时问题
    dede 提交表单 发送邮件
    a 标签中 写页面刷新代码
    织梦dede在首页调用留言本
    PHP通过Thrift操作Hbase
  • 原文地址:https://www.cnblogs.com/330774495qq/p/12855727.html
Copyright © 2011-2022 走看看