Let's say I have a class like this:
Public Class(Of T As Bar) Foo
...
End Class
I'd like to set up something like the following:
Public Class(Of T As Bar) Foo
Public Sub New()
Select T
Case Class1 'Inherits Bar
'do stuff
Case Class2 'Inherits Bar
'do stuff
Case Class3 'Inherits Bar
'do stuff
End Select
End Sub
End Class
Obviously this won't work, but you can probably get the idea of what I'm trying to do from this snippet. So how do you properly determine the Type passed to the constructor in VB.NET? Surprisingly I can't find anything on Stack Overflow about this yet.
C# has the following syntax:
Type typeParameterType = typeof(T);
However,
Dim typeParameterType As Type = TypeOf T
does not work, nor does
Dim typeParameterType As Type = T
C# doesn't allow switch
on typeof
. VB, however, does allow it so you can try something like this:
Public Class Foo(Of T As Bar)
Public Sub New()
Select Case GetType(T)
Case GetType(BarA)
' Do stuff
Case GetType(BarB)
' Do stuff
End Select
End Sub
End Class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With