title: C# reflection : How to set nested Property of nested Lists
body: <p>Imagine following "path" :</p>
  
  <p>MyObject.MyFirstList[0].MySecondList[0].MyProperty = "Hello"</p>
  
  <p>MyProperty is of type String. 
  None of the types is known at compiletime, only runtime via reflection of assembly. </p>
  
  <p>I have everything, but i can not set the second list on the first with SetValue. I always get either null-ref exceptions or "target type does not match". </p>
  
  <p>What I have tried so far:</p>
  
  <p>iteration 1: </p>
  
  <pre><code>var constructedList = Activator.CreateInstance(constructedListType);
  target.GetType().GetProperty(propertyToAdd).SetValue(target, constructedList)
  </code></pre>
  
  <p>Iteration 2:</p>
  
  <p>Same way, works as well. So now we have MyObject.MyFirstList[0].MySecondList[]</p>
  
  <p>Iteration 3: TODO: Create instance of first object of MySecondList and set its MyProperty-property to the created property:</p>
  
  <pre><code>var target = Activator.CreateInstance(typeOfItem);
  target.GetType().GetProperty(propertyToAdd)?.SetValue(target, null);
  </code></pre>
  
  <p>So to summarize the question:</p>
  
  <p>This works: </p>
  
  <pre><code>someInstance.GetType().GetProperty(someProperty).SetValue(someInstance, objToSet);
  </code></pre>
  
  <p>Why does something like this not work? Or does it - if yes, how?</p>
  
  <pre><code>someInstance.GetType().GetProperty(someList.listInsideSomeList.finalProperty).SetValue(...);
  </code></pre>