looping through nested list of object to find properties in c#
<p>I have an object model like this:</p>

<pre><code>public class MyClass
{
  int TheProp {get;set;}
  List&lt;Object1&gt; TheListOfObject1 {get;set;}
  List&lt;Object2&gt; TheListOfObject2 {get;set;}
  List&lt;Object3&gt; TheListOfObject3 {get;set;}  
  List&lt;Object4&gt; TheListOfObject4 {get;set;}
}
</code></pre>

<p>Now some the the nested objects contain a property called MyField and some of the lists might have objects in them and some don't.</p>

<p>I'm looking to loop through every list and if the objects in the list contain the property MyField then set that property to 1.</p>

<p>What's the best way to do this? I could hard-code the loop and only loop through the lists for which I know there's the property I'm looking for and then test if the list has a count > 0 but if I then add another list of nested object I'd have to rewrite that part too. What's a more general way to do it?</p>

<p>Thanks.</p>
