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. How to get value of properties interatively?

How to get value of properties interatively?

Scheduled Pinned Locked Moved C#
questiontutorial
3 Posts 2 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
    moazzamahmed
    wrote on last edited by
    #1

    hi all I have this code: foreach (PropertyInfo pi in this.GetType().GetProperties()) { if (pi.Name != "Ds" && !pi.Name.Contains("nmv") && !pi.Name.Contains("Nmv") && pi.Name != "NewId" && pi.Name != "SpeakerID") nmvParams.Add("@" + pi.Name, pi.ToString()); } "this" is my object that contains all the properties. I need to put the name & values of each property into a namevaluecollection nmvParams. pi.Name gives me the name of the property. How do I get the actual value? pi.ToString() just gives me the name of the property in string. thanks M

    L 1 Reply Last reply
    0
    • M moazzamahmed

      hi all I have this code: foreach (PropertyInfo pi in this.GetType().GetProperties()) { if (pi.Name != "Ds" && !pi.Name.Contains("nmv") && !pi.Name.Contains("Nmv") && pi.Name != "NewId" && pi.Name != "SpeakerID") nmvParams.Add("@" + pi.Name, pi.ToString()); } "this" is my object that contains all the properties. I need to put the name & values of each property into a namevaluecollection nmvParams. pi.Name gives me the name of the property. How do I get the actual value? pi.ToString() just gives me the name of the property in string. thanks M

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      object propval = pi.GetValue(this, new object[0]);

      xacc.ide-0.1.3.9 - Now with Language Designer

      M 1 Reply Last reply
      0
      • L leppie

        object propval = pi.GetValue(this, new object[0]);

        xacc.ide-0.1.3.9 - Now with Language Designer

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

        thanks. I figured it out, its actually pi.GetValue(this, null) but you have to check for null before you run it. M

        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