CType using a variable to hold the type doesn't work
So I do not know at design time if the var ms is going to be a stringreader or a memorystream. So I am trying to do basically this:
Dim ms as object = myfunction...
Dim mytype As Type = ms.GetType
Dim returnedobject = ser.Deserialize(CType(ms, mytype))
But I get an error saying "type mytype is not defined". How can I do this?
Re: CType using a variable to hold the type doesn't work
You can't. A data type and an instance of the Type class are two very different things.
The whole point of casting is that you tell the compiler what the object is. That means that you have to know exactly what the type is when you compile. If you are going to start down the road of Reflection then you must stay on that road. You can't suddenly jump off halfway through.
Re: CType using a variable to hold the type doesn't work
Nested if then statements it is...