views:

64

answers:

1

Hi,

I am trying to use reflection to collect a property from a class that returns a certain type. However some of the properties I'm returning are strongly typed lists that house the type I want. Essentially I am trying to do the following:

Public Function GetPropertyInfo(ByVal t as System.Type)
   for each pi as System.Reflection.PropertyInfo in ob.GetType.GetProperties()
      if pi.PropertyType.equals(GetType(List(Of t)))
         return pi
      end if
   next

   Return Nothing
End Function

Obviously this doesn't work as it throws an error saying t is not a declared type. Is there any way to do this?

Thanks.

+2  A: 

In C#, you are looking for this syntax:

Type desiredPropertyType = typeof(List<>).MakeGenericType(new Type[] { t });

Which reflector says is this:

Dim desiredPropertyType As Type = GetType(List(Of )).MakeGenericType(New Type() { t })
280Z28
Great, worked like a charm. Thanks!
link664