Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can solve your problem by using the following set of classes.</p> <p>First, we need to create a Contains class which will decide which items will be chosen from the source array.</p> <pre><code>class Contains { public bool Value { get; set; } public Contains(object[] items, object item) { Value = (bool)(typeof(Enumerable).GetMethods() .Where(x =&gt; x.Name.Contains("Contains")) .First() .MakeGenericMethod(typeof(object)) .Invoke(items, new object[] { items, item })); } } </code></pre> <p>Then we need to create a Where class which will be used to form a predicate based on which items will be selected. It should be clear that in our case, we are going to use the Contains class for our predicate method.</p> <pre><code>class Where { public object Value { get; set; } public Where(object[] items, object[] items2) { Value = typeof(Enumerable).GetMethods() .Where(x =&gt; x.Name.Contains("Where")) .First() .MakeGenericMethod(typeof(object)) .Invoke(items2, new object[] { items2, new Func&lt;object, bool&gt;(i =&gt; new Contains(items, i).Value) }); } } </code></pre> <p>The last step is simply to invoke the result we got from the Where class, which is actually of type Enumerable.WhereArrayIterator and not of type List, since the result of the Where Extension method is a product of deferred execution.</p> <p>Thus we need to create a non deferred object, by calling its ToList Extension Method, and get our result.</p> <pre><code>class ToList { public List&lt;object&gt; Value { get; set; } public ToList(object[] items, object[] items2) { var where = new Where(items, items2).Value; Value = (typeof(Enumerable).GetMethods() .Where(x =&gt; x.Name.Contains("ToList")) .First() .MakeGenericMethod(typeof(object)) .Invoke(where, new object[] { where })) as List&lt;object&gt;; } } </code></pre> <p>In the end, you can simply test the whole process out by using the following class.</p> <pre><code>class Program { static void Main() { var items = new object[] { 1, 2, 3, 4 }; var items2 = new object[] { 2, 3, 4, 5 }; new ToList(items, items2).Value.ForEach(x =&gt; Console.WriteLine(x)); Console.Read(); } } </code></pre>
    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