Expression拼接

网友投稿 321 2022-06-24


public static class ExpressionHelp

{

///

/// Lambda表达式拼接

///

///

///

///

///

///

public static Expression Compose(this Expression first, Expression second, Func 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(merge(first.Body, secondBody), first.Parameters);

}

///

/// and扩展

///

///

///

///

///

public static Expression> And(this Expression> first, Expression> second)

{

return first.Compose(second, Expression.And);

}

public static Expression> And(this Expression> first, Expression> second)

{

return first.Compose(second, Expression.And);

}

///

/// or扩展

///

///

///

///

///

public static Expression> Or(this Expression> first, Expression> second)

{

return first.Compose(second, Expression.Or);

}

public static Expression> Or(this Expression> first, Expression> second)

{

return first.Compose(second, Expression.Or);

}

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何两个对象数据比对(如何进行两组数据的比对)
下一篇:C#读取ActiveDirectory(乘风破浪的姐姐第三季)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~