Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to Cast dynamically?

How to Cast dynamically?

Scheduled Pinned Locked Moved Visual Basic
questioncsharpvisual-studioxmltutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FruitBatInShades
    wrote on last edited by
    #1

    I'm working on a form editor a.k.a like in Visual Studio and sharpdevelop. I save the forms out as xml mainly using to the .ToString methods and then try to convert them back on load. I thought this would be the way to do it:- Dim PInfo As PropertyInfo = ty.GetProperty(Nde.Name) If Not PInfo Is Nothing Then Dim t As Type = PInfo.GetType() PInfo.SetValue(ctrl, (CType(Nde.Value, PInfo.GetType())), Nothing) End If but CType and DirectCast do not accept PInfo.GetType(). They demand a hand coded type e.g. CType(Value, Integer). Does anybody know of a way to do this? I look for the TagName via reflection :- Dim PInfo As PropertyInfo = ty.GetProperty(Nde.Name) and it returns fine, so it's found the property. But how do I then convert the value to the correct Type so I can set the property value? Demo XML:

    <VISIBLE>True</VISIBLE>
    <Text>Caption :</Text>
    <TextAlign>1</TextAlign>
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups