Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you need it i created a small fluent library to create lambda functions on the fly without directly coping with System.Linq.Expressions. And it can easily handle the kind of situation. Just to give an example:</p> <pre><code>static void Main(string[] args) { var firstNameCompare = ExpressionUtil.GetComparer&lt;FullName&gt;((a) =&gt; a.FirstName); var lastNameCompare = ExpressionUtil.GetComparer&lt;FullName&gt;((a) =&gt; a.LastName); Func&lt;FullName, bool&gt; combined = (a) =&gt; firstNameCompare(a, "Dog") &amp;&amp; lastNameCompare(a, "Boy"); var toCheck = new FullName {FirstName = "Dog", LastName = "Boy"}; Console.WriteLine("Dog Boy should be true: {0}", combined(toCheck)); toCheck = new FullName {FirstName = "Cat", LastName = "Boy"}; Console.WriteLine("Cat Boy should be false: {0}", combined(toCheck)); Console.ReadLine(); } </code></pre> <p>The GetComparer methods seek for the property passed as expression and find ho to get its value, then it builds a new Expression that will handle the comparaison.</p> <p>At the end the two functions are evaluated calling the "combined" function.</p> <p>If you need more verifications you could use an array and iterate on it inside the "combined lambda"</p> <p>The code and documentation for the library are here: <a href="http://kendar.org/?p=/dotnet/expressionsbuilder" rel="nofollow">Kendar Expression Builder</a> While the nuget package is here: <a href="https://www.nuget.org/packages/ExpressionBuilder/" rel="nofollow">Nuget Expression Builder</a></p>
 

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