title: Reflection loop propertes inside a class
body: <p>I can't find a solution to my problem, so I try ask here. I have a class and I want to have a method in the class to test for the state of the Properties. The method should return true if any of the properties has more one or more values assigned. But i cannot find any examples of how to loop trough all the properties of the class itself with reflection and test if Count is &gt; than 0.</p>
  <p>Or should I use another technique than reflection?</p>
  <p>I just want to avoid hard coding the Properties one more time in the Test method.</p>
  <pre><code>using System.Reflection;
  
  public class cP
  {
      public Guid gid { get; set; } = Guid.NewGuid();
      public List&lt;string&gt; p1 { get; set; } = new List&lt;string&gt;();
      public List&lt;string&gt; p2 { get; set; } = new List&lt;string&gt;();
  
      public bool HasDefinedValues()
      {
          List&lt;PropertyInfo&gt; properties = this.GetType().GetProperties().ToList();
  
          foreach (PropertyInfo property in properties)
          {
              if (property.PropertyType == typeof(List&lt;int&gt;))
              {
                  string PName = property.Name;
                  if (((List&lt;int&gt;)property.GetValue(property.Name, null)).Count &gt; 0) { return true; };
              }
          }
  
          return false;
      }
  }
  </code></pre>