title: cast to generic type at runtime
body: <p>Ok, i don't think this is possible so I thought I would ask to make sure. I'm in the process of creating a function which reflects over the properties in a class and adds them to this data structure I have. Some of the properties are generic types. </p>
  
  <p>So say we have <code>DataType(Of T)</code> that has a <code>.Value</code> property of type <code>T</code>:</p>
  
  <pre><code>Dim properties = GetType(MyType).GetFields(Reflection.BindingFlags.Public Or _
                                             Reflection.BindingFlags.Instance)
  For Each prop As fieldinfo In properties
     Collection.Add(prop.Name,prop.GetValue(poco))
  Next
  </code></pre>
  
  <p>In the <code>collection.Add</code> for primitive types (<code>Integer</code>, <code>String</code>, etc.&hellip;) I just want to add the type... but in the case of generic I want to add the <code>DataType(Of T).Value</code>. I hope there is some work-around but I don't think there is a way because the type of <code>T</code> can not be determined at compile time right? Ideally <code>DirectCast(prop.getvalue(poco), DataType(Of T)).Value</code> would be possible. This is when you hoped even more dynamics appear than whats in .NET 4.0.</p>