title: vb.net List of dynamic type
body: <p>I'm building a MVC structure for a part of my program.</p>
  
  <p>I've done the Models of 5-10 tables and what they have in common is only the constructor. (which takes the recordset.fields)</p>
  
  <p>Here's my function to fill these objects:</p>
  
  <pre><code>Public Function reqTable(ByVal pTable As String, ByVal pType As Type, ByVal pNoProjet As Integer, Optional ByVal strAdditionnalConditions As String = "") As List(Of Object)
      Dim lstRetour As List(Of Object) = New List(Of Object)
  
      rsRequestCSV = conSQL.Execute("SELECT * FROM " &amp; pTable &amp; " WHERE NoProjet = " &amp; pNoProjet &amp; " " &amp; strAdditionnalConditions)
      With rsRequestCSV
          While Not .EOF
              lstRetour.Add(Activator.CreateInstance(pType, New Object() {rsRequestCSV.Fields})) 'New clsTable(rsRequestCSV.Fields))
              .MoveNext()
          End While
      End With
      Return lstRetour
  End Function
  </code></pre>
  
  <p>What I'm not able to achieve is to return a List(Of pType) instead of List(Of Object).</p>
  
  <p>The reason I want this is to have headers in my datagridviews even if they're empty.</p>
  
  <p>So is there a way to return a List(Of MyModel'sType) ? </p>
  
  <p>thanks in advance!</p>