title: How to recursively null check the nested object's required properties using reflection
body: <p>Here are my classes with some required properties,</p>
  
  <pre><code>public class Employee
  {
      public EmployeeType employeeType {get; set;}
      public Description description {get; set;}
  }
  
  public class EmployeeType
  {
      public NameType nameField {get; set;}
      public string Address {get; set;}
  }
  
  public class NameType 
  {
      [Required]
      public string FirstName {get; set;}
      [Required]
      public string LastName {get; set;}
      public Role RoleType {get; set;}
  }
  
  public class Role 
  {
      public int RoleId {get; set;}
      [Required]
      public string Name {get; set;}
  }
  
  public class Description
  {
      [Required]
      public string ShortDesciption {get; set;}
      public string LongDescription {get; set;}
  }
  </code></pre>
  
  <p>I have written a method to do a recursive check of properties but it does not go by Required annotation and it would not keep moving forward after finding first property with null value.</p>
  
  <p>Here is my code,</p>
  
  <pre><code>private List&lt;string&gt; GetNullOrEmptyPropertiesList(object myObject)
  {
      List&lt;string&gt; lst = new List&lt;string&gt;();
      foreach (PropertyInfo pi in myObject.GetType().GetProperties())
      {
          if (pi.PropertyType == typeof(string))
          {
              string value = (string)pi.GetValue(myObject);
              if (string.IsNullOrEmpty(value))
              {
                  if (pi.Name == "ShortDescription" || pi.Name == "FirstName")
                  {
                      lst.Add(pi.Name);
                  }
              }
           }
  
           else
           {
               var value = pi.GetValue(myObject);
               return GetNullOrEmptyPropertiesList(value);
           }
       }
  
       return lst;
   }
  </code></pre>