Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this implementation from <a href="http://microsoftnlayerapp.codeplex.com/">Domain Oriented N-Layered .NET 4.0 Sample App</a> (there is also implementation of <a href="http://en.wikipedia.org/wiki/Specification_pattern">specification pattern</a>):</p> <pre><code>public static class ExpressionBuilder { public static Expression&lt;T&gt; Compose&lt;T&gt;(this Expression&lt;T&gt; first, Expression&lt;T&gt; second, Func&lt;Expression, Expression, Expression&gt; merge) { var map = first.Parameters.Select((f, i) =&gt; new { f, s = second.Parameters[i] }).ToDictionary(p =&gt; p.s, p =&gt; p.f); var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body); return Expression.Lambda&lt;T&gt;(merge(first.Body, secondBody), first.Parameters); } public static Expression&lt;Func&lt;T, bool&gt;&gt; And&lt;T&gt;(this Expression&lt;Func&lt;T, bool&gt;&gt; first, Expression&lt;Func&lt;T, bool&gt;&gt; second) { return first.Compose(second, Expression.And); } public static Expression&lt;Func&lt;T, bool&gt;&gt; Or&lt;T&gt;(this Expression&lt;Func&lt;T, bool&gt;&gt; first, Expression&lt;Func&lt;T, bool&gt;&gt; second) { return first.Compose(second, Expression.Or); } } public class ParameterRebinder : ExpressionVisitor { private readonly Dictionary&lt;ParameterExpression, ParameterExpression&gt; map; public ParameterRebinder(Dictionary&lt;ParameterExpression, ParameterExpression&gt; map) { this.map = map ?? new Dictionary&lt;ParameterExpression, ParameterExpression&gt;(); } public static Expression ReplaceParameters(Dictionary&lt;ParameterExpression, ParameterExpression&gt; map, Expression exp) { return new ParameterRebinder(map).Visit(exp); } protected override Expression VisitParameter(ParameterExpression p) { ParameterExpression replacement; if (map.TryGetValue(p, out replacement)) { p = replacement; } return base.VisitParameter(p); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload