title: Invoke ToList() method using reflection at runtime in C#
body: <p>I have a generic as follows.</p>
  
  <pre><code>public class PaginatedList&lt;T&gt; : List&lt;T&gt;
  {...}
  </code></pre>
  
  <p>I simply want to invoke ToList() method on that object at runtime using reflection.</p>
  
  <p>Can someone please help.</p>
  
  <p>I have come so only far.</p>
  
  <pre><code>MethodInfo toListMethod = typeof(Enumerable).GetMethod("ToList");
  var constructedToList = toListMethod.MakeGenericMethod(TypeObjectOfT);
  constructedToList.Invoke(paginatedListObject, null);
  </code></pre>
  
  <p><strong>I get exception</strong> at the last line with message, <strong>Parameter count mismatch</strong>. I feel that the first two steps are ok, as I have checked the <code>toListMethod.ToString()</code> and <code>constructedToList.ToString()</code>. And they have given me the following output, which I feel is correct.</p>
  
  <pre><code>System.Collections.Generic.List`1[TSource] ToList[TSource](System.Collections.Generic.IEnumerable`1[TSource])
  System.Collections.Generic.List`1[AvbhHis.BL.Entities.PatientCategory] ToList[PatientCategory](System.Collections.Generic.IEnumerable`1[AvbhHis.BL.Entities.PatientCategory])
  </code></pre>
  
  <p><strong>Questions:</strong> 
  1. Am I right so far?</p>
  
  <ol start="2">
  <li><p>What should be the parameter to <code>MakeGenericMethod()</code> method. In my case it is the Type of intance of the object of Type T at runtime.</p></li>
  <li><p>There seems to be some problem with the Invoke method call. Is passing null correct as second parameter? The first parameter should be an object of the type PaginatedList right?</p></li>
  </ol>
  
  <p>My energy is out, so kindly help.</p>