title: How do I invoke an extension method using reflection?
body: <p>I appreciate that similar questions have been asked before, but I am struggling to invoke the Linq <strong>Where</strong> method in the following code. I am looking to use reflection to dynamically call this method and also dynamically build the delegate (or lambda) used in the <strong>Where</strong> clause. This is a short code sample that, once working, will help to form part of an interpreted DSL that I am building. Cheers.</p>
  
  <pre><code>    public static void CallWhereMethod()
      {
          List&lt;MyObject&gt; myObjects = new List&lt;MyObject&gt;(){new MyObject{Name="Jon Simpson"}};
          System.Delegate NameEquals = BuildEqFuncFor&lt;MyObject&gt;("Name", "Jon Simpson");
          object[] atts = new object[1] ;
          atts[0] = NameEquals;
  
          var ret = typeof(List&lt;MyObject&gt;).InvokeMember("Where", BindingFlags.InvokeMethod, null, InstanceList,atts);
      }
  
      public static Func&lt;T, bool&gt; BuildEqFuncFor&lt;T&gt;(string prop, object val)
      {
          return t =&gt; t.GetType().InvokeMember(prop,BindingFlags.GetProperty,
                                               null,t,null) == val;
      }
  </code></pre>