Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Is it possible in your test that the Shipment property has not been initialized in your container?</p> <p>A couple other recommendations: If you must use expressions, consider caching the compiled version of the expression so that it can be reused rather than having to recompile it each time you want to use it.</p> <p>Second, is there a specific reason you elected to go with expressions rather than just using Func in your rule? Typically when creating rules engines like this, my rule class is defined as somthing like:</p> <pre><code>public class Rule { public string Description {get; set;} public Func&lt;T, bool&gt; RuleToApply {get; set;} } </code></pre> <p>Given that, I instantiate my Rules collection as follows:</p> <pre><code> var rules = new List&lt;Rule&gt;() { new Rule { Description = "OrderNumber Contains 55", RuleToApply = order =&gt; order.OrderNumber.Contains("55") } }; </code></pre> <p>And PassesRule becomes:</p> <pre><code>public bool PassesRules&lt;T&gt;(List&lt;Rule&gt; rules, T toInspect) { return rules.All(rule =&gt; rule(toInspect)); } </code></pre> <p>The other advantage here is that instead of passing strings and evaulating expressions, I keep the type safety and refactoring support that I would loose by using strings and dynamically building expressions.</p> <p>Another thing to keep in mind if you are building a reusable expression parser, make sure to set up tests in VB as well as C# because they don't always generate the same expression tree under the covers. In particular, add VB tests for string equality (city = "London"). I've seen countless LINQ providers which have overlooked this simple case.</p>
    singulars
    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. 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