VB.NET template instance - passing a variable data type
- by FerretallicA
As the title suggests, I'm tyring to pass a variable data type to a template class. Something like this:
frmExample = New LookupForm(Of Models.MyClass) 'Works fine
Dim SelectedType As Type = InstanceOfMyClass.GetType() 'Works fine
repoGeneric = New Repositories.Repository(Of SelectedType) 'Ba-bow!
repoGeneric = New Repositories.Repository(Of InstanceOfMyClass.GetType()) 'Ba-bow!
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.
(How) can I create an instance of a dynamically typed repository at runtime?