Given a string: \"Person.Address.Postcode\" I want to be able to get/set this postcode property on an instance of Person. How can I do this? My idea was to split the string
Why you don't use recursion? Something like:
setProperyValue(obj, propertyName, value)
{
head, tail = propertyName.SplitByDotToHeadAndTail(); // Person.Address.Postcode => {head=Person, tail=Address.Postcode}
if(tail.Length == 0)
setPropertyValueUsingReflection(obj, head, value);
else
setPropertyValue(getPropertyValueUsingReflection(obj, head), tail, value); // recursion
}