title: How to iterate a C# object, looking for all instances of a specific type, in order to build a separate list of those instances?
body: <p>I have a need that is a bit similar to this <a href="https://stackoverflow.com/questions/6146640/how-to-iterate-a-c-sharp-class-look-for-all-instances-of-a-specific-type-then-c" title="question">question</a>, except that it requires a deeper exploration of the source object.</p>
  
  <p>Here is a code sample:</p>
  
  <pre><code>public class Target {};
  
  public class Analyzed
  {
      public Target EasyOne { get; set; }
      public IList&lt;Target&gt; ABitMoreTricky { get; set; }
      public IList&lt;Tuple&lt;string, Target&gt;&gt; Nightmare { get; set; }
  }
  </code></pre>
  
  <p>From an instance of <code>Analyzed</code>, I want to extract all the <code>Target</code> instances.</p>
  
  <p>In order to ease the exploration, we can assume the following:</p>
  
  <ol>
  <li>Explore only properties.</li>
  <li>There is no infinite reference loop.</li>
  </ol>
  
  <p>For now, <code>EasyOne</code> is... easy, but I am looking for some strategy to get all the <code>Target</code> instances lost in more tricky structures.</p>