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. C#
  4. Casting

Casting

Scheduled Pinned Locked Moved C#
csharptutorial
15 Posts 7 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.
  • J Jaime Olivares

    looks like you need xml deserialization. That is, having an object represented as an xml string, deserialize it in the proper class. Is that the case?

    Best regards, Jaime.

    J Offline
    J Offline
    jojoba2010
    wrote on last edited by
    #6

    No I have string and want to cast it to (color,point,font,...)

    L T 2 Replies Last reply
    0
    • S SeMartens

      Okay, and how does the string look like? E.g. Point(10,20)? I guess you have to write your own method of converting the string to an object.

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      J Offline
      J Offline
      jojoba2010
      wrote on last edited by
      #7

      no it looks like 10,20 for font : Arial for location : 15,19

      S 1 Reply Last reply
      0
      • J jojoba2010

        no it looks like 10,20 for font : Arial for location : 15,19

        S Offline
        S Offline
        SeMartens
        wrote on last edited by
        #8

        And where does the data come from? I mean it could be very difficult to build an algorithm analysing the string itself it is a location or a font name or a color. This could end up in writing a compiler...

        It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

        1 Reply Last reply
        0
        • J jojoba2010

          how to convert (or Cast) string to C# classess

          V Offline
          V Offline
          V 0
          wrote on last edited by
          #9

          From what I read in the thread you're not really helpful in providing information. Note that we don't have any background on what you need to do or what you've done so far. Please elaborate a little on the problem. Where does the input come from? In what format is it set (XML, flat file, CSV,...)? Is there metadata included? What different types of 'classes' are we talking about? etc... If you want help you'll need to be more specific.

          V.

          1 Reply Last reply
          0
          • J jojoba2010

            No I have string and want to cast it to (color,point,font,...)

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #10

            jojoba2010 wrote:

            I have string and want to cast it to (color,point,font,...)

            You cannot do this, a string is just a collection of characters. If you want to create some other object from it then you need to parse the string, extracting the relevant fields and create new objects based on that data. Read the documentation on what casting is, it does not convert one object to another.

            MVP 2010 - are they mad?

            T 1 Reply Last reply
            0
            • J jojoba2010

              how to convert (or Cast) string to C# classess

              A Offline
              A Offline
              AspDotNetDev
              wrote on last edited by
              #11

              The word you are looking for is "parse". Many classes have a "Parse" method. For example:

              int x = int.Parse("1");

              To parse Point strings, you can use the System.Drawing.PointConverter class. For other classes, find the parse methods or create them yourself.

              [Forum Guidelines]

              1 Reply Last reply
              0
              • J jojoba2010

                I want to convert string to (Point,Font,Color,...) ?

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #12

                jojoba2010 wrote:

                Point

                System.Drawing.PointConverter

                jojoba2010 wrote:

                Font

                System.Drawing.FontConverter

                jojoba2010 wrote:

                Color

                System.Drawing.ColorConverter

                [Forum Guidelines]

                1 Reply Last reply
                0
                • J jojoba2010

                  No I have string and want to cast it to (color,point,font,...)

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #13

                  what actuallly coming into your string!

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                  Never mind - my own stupidity is the source of every "problem" - Mixture

                  cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                  1 Reply Last reply
                  0
                  • L Lost User

                    jojoba2010 wrote:

                    I have string and want to cast it to (color,point,font,...)

                    You cannot do this, a string is just a collection of characters. If you want to create some other object from it then you need to parse the string, extracting the relevant fields and create new objects based on that data. Read the documentation on what casting is, it does not convert one object to another.

                    MVP 2010 - are they mad?

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #14

                    Richard MacCutchan wrote:

                    MVP 2010 - are they mad?

                    Nope i don't think so!

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                    Never mind - my own stupidity is the source of every "problem" - Mixture

                    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                    L 1 Reply Last reply
                    0
                    • T ThatsAlok

                      Richard MacCutchan wrote:

                      MVP 2010 - are they mad?

                      Nope i don't think so!

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                      Never mind - my own stupidity is the source of every "problem" - Mixture

                      cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #15

                      You are too kind my friend. :rose:

                      MVP 2010 - are they mad?

                      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