ThankGodItsFriday
Programmer
The problem I'd like to solve is to map a value type to a value in a hashtable in managed code.
In unmanaged code I would simply declare the hashtable as
thus making sure that whenever _aString is modified the value for the key is also modified.
I can solve this by updating ht in the set-statement for each property, however I would like it to work the other way around as well - that is:
I've been looking some in the System.Reflection namespace, but even though this gives my the possibility to return the name of the properties it doesn't seem to give me the ability to set them.
Is this at all possible to to in managed code? As far as I understand MS removed pointers to be able to implement garbage collection more efficiently, but is there a workaround?
// T.G.I.F.
Code:
public class testbase
{
protected HashTable ht = new HashTable();
}
public class test : testbase
{
string _aString;
int _aInt;
public test()
{
ht["aString"] = _aString;
ht["aInt"] = _aInt;
}
public string aString
{
get {return _aString;}
set {_aString = value;}
}
public int aInt
{
get {return _aInt;}
set {_aInt = value;}
}
}
In unmanaged code I would simply declare the hashtable as
Code:
ht["aString"] = &_aString;
thus making sure that whenever _aString is modified the value for the key is also modified.
I can solve this by updating ht in the set-statement for each property, however I would like it to work the other way around as well - that is:
Code:
ht["aString"].value = "A new string"; // should automatically update _aString
I've been looking some in the System.Reflection namespace, but even though this gives my the possibility to return the name of the properties it doesn't seem to give me the ability to set them.
Is this at all possible to to in managed code? As far as I understand MS removed pointers to be able to implement garbage collection more efficiently, but is there a workaround?
// T.G.I.F.