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. accessing members without reflection.

accessing members without reflection.

Scheduled Pinned Locked Moved C#
data-structurescryptographydiscussion
6 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.
  • U Offline
    U Offline
    User 2322509
    wrote on last edited by
    #1

    I have this scenario: I have hash table with keys are same as private member variable names something like below: key ---- value -------------------- m_strID ---- "123" m_strName ---- "xyz" Now without writing any loop and case statement i want to assign values from hashtable to my class local variables: I don't want to do like below as i have to hard code things: foreach (string key in hashtable.keys) { switch(key) { case "m_strID": (local member) m_strID = value } } Even i don't want to use reflection, i guess, it has some overhead. I can't think of any other way. Any thoughts are appreciated. Thanks.

    0 M 2 Replies Last reply
    0
    • U User 2322509

      I have this scenario: I have hash table with keys are same as private member variable names something like below: key ---- value -------------------- m_strID ---- "123" m_strName ---- "xyz" Now without writing any loop and case statement i want to assign values from hashtable to my class local variables: I don't want to do like below as i have to hard code things: foreach (string key in hashtable.keys) { switch(key) { case "m_strID": (local member) m_strID = value } } Even i don't want to use reflection, i guess, it has some overhead. I can't think of any other way. Any thoughts are appreciated. Thanks.

      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #2

      I don't think that's possible without Reflection. The overhead would only really be noticed if you loop several hundred times anyway, so there really isn't any need to worry if you're just putting together a small application

      U 1 Reply Last reply
      0
      • 0 0x3c0

        I don't think that's possible without Reflection. The overhead would only really be noticed if you loop several hundred times anyway, so there really isn't any need to worry if you're just putting together a small application

        U Offline
        U Offline
        User 2322509
        wrote on last edited by
        #3

        Thanks for the reply, i just want to confirm that there is no other way without reflection and am not missing any good logic. This bit which i am talking about is used in my serialize and deserialize process. Even there are few members (about 50), its going to be executed many times (every time i send a query across wire). Even MS logic for finding the serializable members and serializing uses reflection (hope i am not wrong).

        1 Reply Last reply
        0
        • U User 2322509

          I have this scenario: I have hash table with keys are same as private member variable names something like below: key ---- value -------------------- m_strID ---- "123" m_strName ---- "xyz" Now without writing any loop and case statement i want to assign values from hashtable to my class local variables: I don't want to do like below as i have to hard code things: foreach (string key in hashtable.keys) { switch(key) { case "m_strID": (local member) m_strID = value } } Even i don't want to use reflection, i guess, it has some overhead. I can't think of any other way. Any thoughts are appreciated. Thanks.

          M Offline
          M Offline
          Mbah Dhaim
          wrote on last edited by
          #4

          see system.runtime.serialization[^] hope it helps

          dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

          modified on Tuesday, March 17, 2009 3:27 PM

          U 1 Reply Last reply
          0
          • M Mbah Dhaim

            see system.runtime.serialization[^] hope it helps

            dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

            modified on Tuesday, March 17, 2009 3:27 PM

            U Offline
            U Offline
            User 2322509
            wrote on last edited by
            #5

            Dhaim, we are implemented ISerializable in our classed and handling serialization ourself. I am looking more optimized code for serializing objects on ourown.

            N 1 Reply Last reply
            0
            • U User 2322509

              Dhaim, we are implemented ISerializable in our classed and handling serialization ourself. I am looking more optimized code for serializing objects on ourown.

              N Offline
              N Offline
              Natza Mitzi
              wrote on last edited by
              #6

              If you are looking for a faster way and less space, serialize the bytes your self using BitConverter class (static methods). The downside is that you need to hand code all of this unless you build a little SW that will do it for you.

              Natza Mitzi

              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