title: How to cast an object to a List
body: <p>I have an object which is actually a List. I have a string what the element type is but I don't know how to cast the object to a List? Here is some code depicting my problem.</p>
  
  <pre><code>class Data
  {
      public int ID { get; set; }
      public List&lt;double&gt; Values { get; set; }
  }
  
  static void Main(string[] args)
  {
      Data d = new Data() { ID = 69, Values = new List&lt;double&gt;() };
      d.Values.Add(1.0);
      d.Values.Add(2.0);
  
      PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(Data));
      var propInfo = typeof(Data).GetProperties();
  
      foreach (var p in propInfo)
      {
          var Value = p.GetValue(d, null);
          var Type = p.PropertyType;
  
          if (Type.IsGenericType &amp;&amp; Type.GetGenericTypeDefinition() == typeof(List&lt;&gt;))
          {
              // get the element type of a list
              var ElementType = Value.GetType().GetProperty("Item").PropertyType;
  
              // how to cast to List&lt; "ElementType" &gt; ???
          }
          else
          {
              types.Add( Type.FullName );
          }
      }
  }
  </code></pre>