title: Dynamically creating Where clause using Expressions
body: <p>I have to dynamically create a Where clause using expressions in the following manner:</p>
  
  <pre><code>Type enumerableType = typeof(Enumerable);
  MemberInfo[] members = enumerableType.GetMember("Where*");
  MethodInfo whereDef = (MethodInfo)members[0]; 
  Type TSource = whereDef.GetGenericArguments()[0]; 
  Type[] types = 
  { 
      typeof(IEnumerable&lt;&gt;).MakeGenericType(TSource), 
      typeof(Func&lt;,&gt;).MakeGenericType(TSource, typeof(Boolean)) 
  };
  
  MethodInfo method = enumerableType.GetMethod("Where", types);
  
  Expression.Call(null, method , new Expression[]
  {
      Expression.Lambda(newEX,new ParameterExpression[]{param})
  });
  </code></pre>
  
  <p>The problem I am facing is that at <code>Expresssion.call</code> I am getting the following error:</p>
  
  <blockquote>
    <p>Method System.Collections.Generic.IEnumerable`1[TSource]
    Where[TSource](System.Collections.Generic.IEnumerable`1[TSource],
    System.Func`2[TSource,System.Boolean]) is a generic method definition</p>
  </blockquote>
  
  <p>Can some one tell me how to overcome this problem?</p>
  
  <p>P.S: The Expression tree was built by referencing the code generated with reflector. In reflector the code is given as below:</p>
  
  <pre><code>Expression.Call(null, (MethodInfo) methodof(Enumerable.Where), 
      new Expression[] ...
  </code></pre>