At the moment, my code is successfully setting the value of the fields / properties / arrays of the object using reflection, given the path to the field / property from the root object.
eg.
SetValue('MySubProperty/MyProperty', 'new value', MyObject);
In the above example, the 'MyProperty' property of the MyObject object for 'new value'
I cannot use reflection to set the value of a field in a structure that is part of an array of structures, because struct is a value type (inside the array).
Here are some test classes / structures ...
public class MyClass {
public MyStruct[] myStructArray = new MyStruct[] {
new MyStruct() { myField = "change my value" }
};
public MyStruct[] myOtherStructArray = new MyStruct[] {
new MyStruct() { myOtherField = "change my value" },
new MyStruct() { myOtherField = "change my other value" }
};
}
public struct MyStruct { public string myField; public string myOtherField; }
The following shows how I successfully set the value of normal properties / fields and details / fields in lists ...
public void SetValue(string pathToData, object newValue, object rootObject)
{
object foundObject = rootObject;
foreach (string element in pathToData.Split("/"))
{
foundObject =
foundObject =
}
FieldInf.SetValue(foundObject, newValue);
}
object myObject = new MyClass();
SetValue("/myStructArray/[0]/myField", "my new value", myObject);
SetValue("/myOtherStructArray/[1]/myOtherField", "my new value", myObject);
myObject.myStructArray [0].myField = '' "
myObject.myOtherStructArray [1].myOtherField = '' "
, , "FieldInf.SetValue" (foundObject, newValue);