Hi guys,
How do you do dynamic type switching? What I need to be able to do is change the type of an object based on a string.
For example
VB Code:
myObject = CType(passedObject, "System.String")
I've tried something along the lines of.
VB Code:
Dim myType As Type Dim strType As String = "System.String" Dim myObject As Object myType = System.Type.GetType(strType) myObject = CType(passedObject, myType)
Where strType could obviously be anything.
.Net is complaining that it cannot find the type of myType. So how do I accomplish doing type conversions when I don't know the type I want to convert to until runtime. (I know I could do a large select case, but I'd rather avoid this.)




Reply With Quote