I have the following code to get the object type of a collection:
Dim objType As Type = myCollection.[GetType]().GetProperty("Item").PropertyType
That line seems to work, but then I need to convert the collection to a datatable specifying the type of the collection, what is the correct way to pass the object type as parameter?
I’m trying:
DataTableCollectionConverter.ConvertToDataTable(Of objType)(myCollection)
but it is not even recognized as valid code
I’m using VS 2005, Net 2.0
Thanks in advance.
You can’t use variables, even of type
Type, in as type parameters for generics. They have to be compiled up-front, not at run-time. That’s why the compiler is complaining.You’ll have to use a weakly-typed version of that method, rely on reflection in some way or use a switch statement to provide the right type parameter to the generic method.