title: Tranform and Apply Expression via LINQ?
body: <p>I am looking to support "expression passthru" as follows:</p>
  
  <pre><code>public IFastIndexingCollection&lt;T&gt; {
     // Main data structure here = 
     // Key = property name
     // Value = class below
     private Dictionary&lt;string, ICustomCollection&lt;T, U&gt;&gt; _indexedItems;
  
     public IEnumerable&lt;T&gt; FindWhere(Expression&lt;Func&lt;T, bool&gt;&gt; expression);
  }
  
  internal ICustomCollection&lt;T, U&gt; {
       // Main data structure =
       // T = type of data structure, e.g., Phone
       // U = property type, e.g., string
       // Key = value for given property (e.g., "Samsung")
       // Value = List&lt;T&gt; of items matching that key
       private ILookup&lt;U, T&gt; _backingLookup;
  }
  </code></pre>
  
  <p>The trouble comes when we're trying to pass the LINQ expression through to the custom list. Say the user executes:</p>
  
  <pre><code>&lt;T&gt; = Phone
  FastIndexingCollection&lt;Phone&gt;.FindWhere(x =&gt; x.Manufacturer.IndexOf("Samsung") &gt; -1);
  </code></pre>
  
  <p>In this case, the code has to:</p>
  
  <ol>
  <li>Figure out that the property in question is named "Manufacturer" and pull the relevant values(s) out of the dictionary for <code>key = "Manufacturer"</code></li>
  <li>Pass to, or otherwise transform, the expression so that the <code>ICustomCollection</code> dictionary value can actually recognize; <code>typeof(Manufacturer) = U = string</code>. So in my example of <code>x.Manufacturer.IndexOf(...)</code>, the "transformed" expression really doesn't need <code>x.Manufacturer</code> anymore because that's not stored in the lookup.</li>
  <li>Execute a LINQ expression on the lookup that <code>ICustomCollection</code> is using</li>
  </ol>
  
  <p>I've pulled the expression body off of the topmost expression to get the MethodInfo off of it, and can get to the right dictionary key value pair, but I can't figure out how to transform the LINQ expression so that so I can apply it on the "lowest" level <code>_backingLookup</code>: I tried to do something like:</p>
  
  <pre><code>foreach(var kvp in _backingLookup)
  {
     if(...need to apply LINQ expression here... == true)
     {
          // Add _internalLookup[kvp.Key] to return value
     }
  }
  </code></pre>
  
  <p>I just can't figure out how to apply the LINQ expression where indicated in the if. Ideas?</p>