title: Dynamic expression on List<T>
body: <p>Given the following classes </p>
  
  <pre><code>public class ClassA
  {
      public string StringProperty { get; set; }
  
      public List&lt;ClassB&gt; List { get; set; }
  }
  
  public class ClassB 
  {
      public int IntProperty { get; set; }
  }
  </code></pre>
  
  <p>I Would like to dynamically create an expression like the following</p>
  
  <pre><code>x =&gt; x.StringProperty == "X" &amp;&amp; x.List.Any( y =&gt; y.IntProperty &gt; 1 )
  </code></pre>
  
  <p>No problem for the first part (<code>x.StringProperty == "X"</code>). For the second part I have created a member expression corresponding to <code>x.List</code> and now need to </p>
  
  <ol>
  <li>Create the inner lambda. To do this I need to know the type of <code>y</code> which is actually the same inner type of <code>x.List</code></li>
  <li>Call the Any method on the x.List expression</li>
  </ol>
  
  <p>Any hint on the first point? How do I get the type T of an <code>IEnumerable&lt;T&gt;</code>?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have tried with the following code but it returns null unfortunately</p>
  
  <pre><code>//This expression will be x.List of my original sample 
  MemberExpression expr = GetMemberExpression( property, pe );
  
  Type innerType = expr.GetType()
                       .GetInterfaces()
                       .Where( t =&gt; t.IsGenericType == true &amp;&amp; t.GetGenericTypeDefinition() == typeof( IEnumerable&lt;&gt; ) )
                       .Select( t =&gt; t.GetGenericArguments()[0] )
                       .SingleOrDefault();
  </code></pre>