title: Get property values from complex model in C#
body: <p>I want to obtain the values of properties of a complex model (IList(Object) in object)). I find the the main properties of the parent object and also the type of the childobject which I need. But I cannot extract its values.</p>
  
  <p>I think the issue is due to the obect parameter in the GetValue method. It needs to be the "TheMovieDatabaseModelDetails" object. I've tried a lot of various options here, but get the error: "object does not match target type".</p>
  
  <p>Model:</p>
  
  <pre><code>public class TheMovieDatabaseModel
  {
      public int page { get; set; }
      public int total_results { get; set; }
      public int total_pages { get; set; }
      public IList&lt;TheMovieDatabaseModelDetails&gt; results { get; set; }
  }
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>private async Task GetMovieDetailsForTheMovieDatabase&lt;T&gt;(T movieModel)
          {
              PropertyInfo[] propertyInfo = movieModel.GetType().GetProperties();
              foreach (PropertyInfo property in propertyInfo)
              {
                  if (property.Name.Equals("results"))
                  {
                      var movieDetails = property.GetType().GetProperties();
                      foreach (var detail in movieDetails)
                      {
                          detail.GetValue(movieDetails, null); // here I need to fill in the right "object".
                      }
                  }
  
                  // etc..
              }
          }
  </code></pre>
  
  <p>research (amongst others):
  <a href="https://stackoverflow.com/questions/21091452/get-values-from-complex-class-using-reflection">Get Values From Complex Class Using Reflection</a> </p>