VB.NET template instance - passing a variable data type
Posted
by FerretallicA
on Stack Overflow
See other posts from Stack Overflow
or by FerretallicA
Published on 2010-06-02T00:52:05Z
Indexed on
2010/06/02
0:53 UTC
Read the original article
Hit count: 251
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?
© Stack Overflow or respective owner