accessing members without reflection.
-
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.
-
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.
-
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
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).
-
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.
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
-
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
Dhaim, we are implemented ISerializable in our classed and handling serialization ourself. I am looking more optimized code for serializing objects on ourown.
-
Dhaim, we are implemented ISerializable in our classed and handling serialization ourself. I am looking more optimized code for serializing objects on ourown.
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