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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Exists an interface for Parse(string value) method and ToString(string format)?

Exists an interface for Parse(string value) method and ToString(string format)?

Scheduled Pinned Locked Moved C#
question
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
    machocr
    wrote on last edited by
    #1

    Hi I wat to pass objects than have ToString(strig Format) and Parse(string value) in method's parameter. So I want to know what interface use for pass double, int, datetime, etc. that have these methods public void AddFormat( iteface? param,string format) { this.txtValue.Text = param.ToString(format); } public object GetValue() { return myObject.Parse(this.txtValue.Text); } Thank you :cool: La realidad no es más que impulsos eléctricos del cerebro - Morpheus

    M 1 Reply Last reply
    0
    • M machocr

      Hi I wat to pass objects than have ToString(strig Format) and Parse(string value) in method's parameter. So I want to know what interface use for pass double, int, datetime, etc. that have these methods public void AddFormat( iteface? param,string format) { this.txtValue.Text = param.ToString(format); } public object GetValue() { return myObject.Parse(this.txtValue.Text); } Thank you :cool: La realidad no es más que impulsos eléctricos del cerebro - Morpheus

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

      Maybe you must pass param as object? Then you can pass in everything you want (enum, int, float, double, etc.). Pompiedompiedom... ;)


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

      M 1 Reply Last reply
      0
      • M Marc 0

        Maybe you must pass param as object? Then you can pass in everything you want (enum, int, float, double, etc.). Pompiedompiedom... ;)


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

        M Offline
        M Offline
        machocr
        wrote on last edited by
        #3

        Yes but I want only objects that have ToString(string format) and Parse(string value), like int,double, datetime and others. ;P La realidad no es más que impulsos eléctricos del cerebro - Morpheus

        S 1 Reply Last reply
        0
        • M machocr

          Yes but I want only objects that have ToString(string format) and Parse(string value), like int,double, datetime and others. ;P La realidad no es más que impulsos eléctricos del cerebro - Morpheus

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          I guess you'll have to use reflection for that.

          public object GetValue()
          {
          MethodInfo method = myObject.GetType().GetMethod("Parse");
          ParameterInfo[] parameterList = method.GetParameters();
          if (parameterList.Count == 1 && parameter[0].ParameterType == typeof(string))
          {
          method.Invoke(...);
          }
          }

          Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          M 1 Reply Last reply
          0
          • S S Senthil Kumar

            I guess you'll have to use reflection for that.

            public object GetValue()
            {
            MethodInfo method = myObject.GetType().GetMethod("Parse");
            ParameterInfo[] parameterList = method.GetParameters();
            if (parameterList.Count == 1 && parameter[0].ParameterType == typeof(string))
            {
            method.Invoke(...);
            }
            }

            Regards Senthil _____________________________ My Blog | My Articles | WinMacro

            M Offline
            M Offline
            machocr
            wrote on last edited by
            #5

            :omg: wow is a good aproach. I really like when peopple answer question i differents ways! I theink a use it. Thank you very much!!! :cool: La realidad no es más que impulsos eléctricos del cerebro - Morpheus

            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