We already have typename::GetVariableValue to dynamically get variables of known correct out variable type. I would like to have a corresponding method of typename::SetVariableValue(Class var, int vIdx, out void val).
My goal is to replace the expensive deep copy setup for some of my data that are currently going through JSON with a combination of Managed::Clone() for shallow copies and then go through and add deeper copies on complex class members recursively so I end up with a full truly deep copy.
This is currently not possible because even though I can create a copy for a complex member, there is no way to assign that copy back to the destination instance dynamically. All I get back is a Managed instance, and to assign it I would need to put it into the correct compile-time type. My code however handles user types so I can not possibly know their types in my logic and need to resort to this dynamic scripting.
class TestThingy { int someProp; } class TestHolder { string someString; ref TestThingy someRef; }
That would be solved if for the above I could do:
void Copy(Managed instance) { foreach(prop on instance) { if(prop is complex) { Managed complexProp; instance.Type().GetVariableVale(instance, propVIdx, complexProp); instance.Type().SetVariableValue(instance, propVIdx, complexProp.Clone()); } } }