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. dynamically address class vairables [modified]

dynamically address class vairables [modified]

Scheduled Pinned Locked Moved C#
helpquestion
6 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.
  • S Offline
    S Offline
    shwaguy
    wrote on last edited by
    #1

    Is there a way to convert a string type into a variable type: "string" > this."string"? The effect I am looking for would be like the dynamic at runtime statement"this.'string' = 'the strings value'" sets a vaulue for the static compile time value "this.stringName" Any comments or help? Class MyClass { private string cn; private string sn; ///I know.....not correct syntax string this.cn = cn; string this.sn = sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { this.cn = (string)result.Properties[cn][0]; //I want the above to become something like this //this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy -- modified at 12:18 Friday 23rd November, 2007

    M L 2 Replies Last reply
    0
    • S shwaguy

      Is there a way to convert a string type into a variable type: "string" > this."string"? The effect I am looking for would be like the dynamic at runtime statement"this.'string' = 'the strings value'" sets a vaulue for the static compile time value "this.stringName" Any comments or help? Class MyClass { private string cn; private string sn; ///I know.....not correct syntax string this.cn = cn; string this.sn = sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { this.cn = (string)result.Properties[cn][0]; //I want the above to become something like this //this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy -- modified at 12:18 Friday 23rd November, 2007

      M Offline
      M Offline
      Mustafa Ismail Mustafa
      wrote on last edited by
      #2

      shwaguy wrote:

      Is there a way to convert a string type into a variable type: "string" > this."string"?

      ??? :confused: huh? Can you rephrase your question?

      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

      1 Reply Last reply
      0
      • S shwaguy

        Is there a way to convert a string type into a variable type: "string" > this."string"? The effect I am looking for would be like the dynamic at runtime statement"this.'string' = 'the strings value'" sets a vaulue for the static compile time value "this.stringName" Any comments or help? Class MyClass { private string cn; private string sn; ///I know.....not correct syntax string this.cn = cn; string this.sn = sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { this.cn = (string)result.Properties[cn][0]; //I want the above to become something like this //this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy -- modified at 12:18 Friday 23rd November, 2007

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        have a look at the System.Reflection namespace. There are several articles about reflection here on CP. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


        M 1 Reply Last reply
        0
        • L Luc Pattyn

          have a look at the System.Reflection namespace. There are several articles about reflection here on CP. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


          M Offline
          M Offline
          Mustafa Ismail Mustafa
          wrote on last edited by
          #4

          you actually understood what was meant? what was it?

          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

          L 1 Reply Last reply
          0
          • M Mustafa Ismail Mustafa

            you actually understood what was meant? what was it?

            "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            the question was: "If I have the name of an existing field/method/property in a string, how can I access that particular field/method/property?" or something completely different. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


            M 1 Reply Last reply
            0
            • L Luc Pattyn

              the question was: "If I have the name of an existing field/method/property in a string, how can I access that particular field/method/property?" or something completely different. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


              M Offline
              M Offline
              Mustafa Ismail Mustafa
              wrote on last edited by
              #6

              ah! Well, I'm glad you were able to understand what was wanted, because I sure didn't! :laugh:

              "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

              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