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. Reflection

Reflection

Scheduled Pinned Locked Moved C#
questiondata-structures
5 Posts 4 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
    SirMorrisBig
    wrote on last edited by
    #1

    Hello world! I have a class and I wish to get a reference to one of its member variables at runtime. class foo { public string bar1; public string bar2; .. } I have called foo.GetFields() and I am the proud owner of an array of FieldInfo structures giving me information about all of the type's member variables. I can see my strings (checkboxes/bears) in the list. My question is: How can I take this FieldInfo data, and get a reference to the desired variable and hence manipulate it?? Many thanks in advance, Charlie (C:=

    H C 2 Replies Last reply
    0
    • S SirMorrisBig

      Hello world! I have a class and I wish to get a reference to one of its member variables at runtime. class foo { public string bar1; public string bar2; .. } I have called foo.GetFields() and I am the proud owner of an array of FieldInfo structures giving me information about all of the type's member variables. I can see my strings (checkboxes/bears) in the list. My question is: How can I take this FieldInfo data, and get a reference to the desired variable and hence manipulate it?? Many thanks in advance, Charlie (C:=

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You've already got it: the FieldInfo. If you want to get or set a field's value, use FieldInfo.GetValue and FieldInfo.SetValue. If the fields are instance fields, you must pass the object whos fields you want to retreive.

      Microsoft MVP, Visual C# My Articles

      S 1 Reply Last reply
      0
      • S SirMorrisBig

        Hello world! I have a class and I wish to get a reference to one of its member variables at runtime. class foo { public string bar1; public string bar2; .. } I have called foo.GetFields() and I am the proud owner of an array of FieldInfo structures giving me information about all of the type's member variables. I can see my strings (checkboxes/bears) in the list. My question is: How can I take this FieldInfo data, and get a reference to the desired variable and hence manipulate it?? Many thanks in advance, Charlie (C:=

        C Offline
        C Offline
        Christer Claesson
        wrote on last edited by
        #3

        Where does foo and bar come from, as it seems to be standard in using in examples? Does it come from FUBAR? Thanks :-)

        M 1 Reply Last reply
        0
        • C Christer Claesson

          Where does foo and bar come from, as it seems to be standard in using in examples? Does it come from FUBAR? Thanks :-)

          M Offline
          M Offline
          MyBlindy
          wrote on last edited by
          #4

          yes... now, what's a fubar?

          /* Peace and love,
          * Tweety
          */

          1 Reply Last reply
          0
          • H Heath Stewart

            You've already got it: the FieldInfo. If you want to get or set a field's value, use FieldInfo.GetValue and FieldInfo.SetValue. If the fields are instance fields, you must pass the object whos fields you want to retreive.

            Microsoft MVP, Visual C# My Articles

            S Offline
            S Offline
            SirMorrisBig
            wrote on last edited by
            #5

            Thanks!! (C:= Charlie.

            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