|
-
Nov 14th, 2010, 11:55 PM
#1
Thread Starter
Lively Member
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?
-
Nov 15th, 2010, 12:42 AM
#2
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.
-
Nov 15th, 2010, 12:54 AM
#3
Thread Starter
Lively Member
Re: CType using a variable to hold the type doesn't work
Nested if then statements it is...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|