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. .NET (Core and Framework)
  4. object = (string + type) ?

object = (string + type) ?

Scheduled Pinned Locked Moved .NET (Core and Framework)
tutorialquestioncsharpcomxml
5 Posts 3 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.
  • M Offline
    M Offline
    Marc 0
    wrote on last edited by
    #1

    Hey everybody! I have a question. I'm trying to do some dynamic property loading from an xml file. So i know the following things from the xml: 1) the type of the object to initialize 1) what property of the object to initialize 2) the value the property should get in the form of a string 3) the type of the property (i got that one from the propertyinfo) I know there has to be a method that you pass a type and a string, and it creates the object for you, just like the propertygrid. I don't want to write a huge switch statement... Example:

    // I know how to get the 5.4 as a string, but not how to make it a float...
    <Roundness>5.4</Roundness> ---> blabla.Roundness = 5.4!

    Thank you! :)


    "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


    || Fold With Us! || Pensieve || VG.Net ||

    R D 2 Replies Last reply
    0
    • M Marc 0

      Hey everybody! I have a question. I'm trying to do some dynamic property loading from an xml file. So i know the following things from the xml: 1) the type of the object to initialize 1) what property of the object to initialize 2) the value the property should get in the form of a string 3) the type of the property (i got that one from the propertyinfo) I know there has to be a method that you pass a type and a string, and it creates the object for you, just like the propertygrid. I don't want to write a huge switch statement... Example:

      // I know how to get the 5.4 as a string, but not how to make it a float...
      <Roundness>5.4</Roundness> ---> blabla.Roundness = 5.4!

      Thank you! :)


      "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


      || Fold With Us! || Pensieve || VG.Net ||

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      I'm not exactly sure but do you probably mean Convert.ChangeType(myString, myType);?

      M 1 Reply Last reply
      0
      • R Robert Rohde

        I'm not exactly sure but do you probably mean Convert.ChangeType(myString, myType);?

        M Offline
        M Offline
        Marc 0
        wrote on last edited by
        #3

        That was not the method i was looking for, because you can't convert everything from a string that way. But it did help me in the right direction, so thank you very much! :-D I ended up writing a method by myself, it wasn't so hard as i thought it would be. :)


        "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


        || Fold With Us! || Pensieve || VG.Net ||

        1 Reply Last reply
        0
        • M Marc 0

          Hey everybody! I have a question. I'm trying to do some dynamic property loading from an xml file. So i know the following things from the xml: 1) the type of the object to initialize 1) what property of the object to initialize 2) the value the property should get in the form of a string 3) the type of the property (i got that one from the propertyinfo) I know there has to be a method that you pass a type and a string, and it creates the object for you, just like the propertygrid. I don't want to write a huge switch statement... Example:

          // I know how to get the 5.4 as a string, but not how to make it a float...
          <Roundness>5.4</Roundness> ---> blabla.Roundness = 5.4!

          Thank you! :)


          "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


          || Fold With Us! || Pensieve || VG.Net ||

          D Offline
          D Offline
          Daniel Grunwald
          wrote on last edited by
          #4

          System.ComponentModel.TypeConverter tc = System.ComponentModel.TypeDescriptor.GetConverter(typeof(ElementType)); Then use tc.ConvertFromInvariantString / tc.ConvertToInvariantString. Works for int, float, Point, Font, etc...

          M 1 Reply Last reply
          0
          • D Daniel Grunwald

            System.ComponentModel.TypeConverter tc = System.ComponentModel.TypeDescriptor.GetConverter(typeof(ElementType)); Then use tc.ConvertFromInvariantString / tc.ConvertToInvariantString. Works for int, float, Point, Font, etc...

            M Offline
            M Offline
            Marc 0
            wrote on last edited by
            #5

            Ah TypeDescriptor, that's the one! That is a lot easier than looking for TypeConverterAttributes and stuff. Thank you so much man! :jig:


            "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


            || Fold With Us! || Pensieve || VG.Net ||

            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