Results 1 to 6 of 6

Thread: Dynamic Type Handling [Resolved]

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153

    Question Dynamic Type Handling [Resolved]

    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:
    1. myObject = CType(passedObject, "System.String")

    I've tried something along the lines of.

    VB Code:
    1. Dim myType As Type
    2. Dim strType As String = "System.String"
    3. Dim myObject As Object
    4.  
    5. myType = System.Type.GetType(strType)
    6.  
    7. 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.)
    Last edited by Carnifex; Dec 29th, 2003 at 07:20 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width