title: How do I use reflection to access an IEnumerable member within a type?
body: <p>How do I access IEnumerable members within a type.</p>
  <p>In this case, the <em>Likes</em> property is never exposed in the <em>Retrieve</em> method of the <em>References</em> class.</p>
  <pre><code>[Test]
  public void Test1()
  {
      // Setup
      var person          = new Person(&quot;some_id&quot;, &quot;John&quot;, &quot;Doe&quot;, new List&lt;string&gt;{ &quot;Dogs&quot; });
      var persons         = new List&lt;Person&gt; () { person };
      var valuePredicates = new List&lt;Predicate&lt;string&gt;&gt;() { v =&gt; v.EndsWith(&quot;Id&quot;) };
  
      // Test
      var references = References.Retrieve(person, new List&lt;KeyValuePair&lt;string,string&gt;&gt;(), valuePredicates);
  }
  </code></pre>
  <p>}</p>
  <pre><code>public static class References
  {
      public static IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; Retrieve(object obj, List&lt;KeyValuePair&lt;string, string&gt;&gt; entries, IEnumerable&lt;Predicate&lt;string&gt;&gt; predicates)
      {
          var type = obj.GetType();
  
          if (type.IsPrimitive || type == typeof(string)) return entries;
  
          var structure = type.Name;
  
          foreach (PropertyInfo property in type.GetProperties(
                      BindingFlags.GetProperty | 
                      BindingFlags.Public      | 
                      BindingFlags.Instance).Where(
                      x =&gt; x.CanRead &amp;&amp;
                      x.GetGetMethod(false) != null &amp;&amp;
                      x.GetIndexParameters().Length == 0))
          {
              var getMethod = property.GetGetMethod(true);
  
              if (getMethod != null)
              {
                  foreach (var isPropertyOfName in predicates)
                  {
                      if (isPropertyOfName(property.Name))
                      {
                          var identifier = $&quot;{structure}::{property.Name}&quot;;
                          var textValue  = property.GetValue(obj) as string;
                          entries.Add(new KeyValuePair&lt;string, string&gt;(identifier, textValue));
                      }
                  }
  
                  Retrieve(getMethod.Invoke(obj, null), entries, predicates);
              }
          }
  
          return entries;
      }
  </code></pre>
  <p><strong>Appendix:</strong></p>
  <pre><code>public class Person
  {
      public Person(string id, string firstName, string lastName, IEnumerable&lt;string&gt; likes) =&gt;
          (Id, FirstName, LastName, Likes) = (id, firstName, lastName, likes);
  
      public string Id { get; }
      public string FirstName { get; }
      public string LastName { get; }
  
      public IEnumerable&lt;string&gt; Likes { get; }
  }
  </code></pre>