title: .NET generic class instance - passing a variable data type
body: <p>As the title suggests, I'm tyring to pass a variable data type to a template class. Something like this:</p>
  
  <pre><code>frmExample = New LookupForm(Of Models.MyClass) 'Works fine
  
  Dim SelectedType As Type = InstanceOfMyClass.GetType() 'Works fine
  frmExample = New LookupForm(Of SelectedType) 'Ba-bow!
  frmExample = New LookupForm(Of InstanceOfMyClass.GetType()) 'Ba-bow!
  </code></pre>
  
  <hr>
  
  <pre><code>LookupForm&lt;Models.MyClass&gt; frmExample;
  Type SelectedType = InstanceOfMyClass.GetType();
  frmExample = new LookupForm&lt;SelectedType.GetType()&gt;(); //Ba-bow
  frmExample = new LookupForm&lt;(Type)SelectedType&gt;(); //Ba-bow
  </code></pre>
  
  <p>I'm assuming it's something to do with the template being processed at compile time but even if I'm off the mark there, it wouldn't solve my problem anyway. I can't find any relevant information on using Reflection to instance template classes either.</p>
  
  <p>(How) can I create an instance of a dynamically typed repository at runtime?</p>