title: Casting Results from Generic Method Invocation?
body: <p>I'm currently messing about with generics and I'm trying to write a function that I can call to load everything from a database table simply by specifying the table name.</p>
  
  <p>I'm most of the way there; my generic methods all seem to work, but I'm not quite sure how to cast my results into something usable.</p>
  
  <p>This is the guts of the method so far:</p>
  
  <pre><code>private static List&lt;EntityCodeBase&gt; GetCodeLoadResults(CodeTables table)
  {
      List&lt;EntityCodeBase&gt; results = new List&lt;EntityCodeBase&gt;();
      Assembly assm = Assembly.Load(new System.Reflection.AssemblyName("RR"));
      Type tableType = assm.GetTypes().Where(u =&gt; u.Name.ToLower() == table.ToString().ToLower()).FirstOrDefault();
      MethodInfo mi = typeof(SpecificEntity).GetMethod("LoadAll");
  
      mi = mi.MakeGenericMethod(tableType);
      mi.Invoke(null, null); //how can I cast the resulting object into a List&lt;EntityCodeBase&gt; ?
  
      return results;
  }
  </code></pre>