Reflection and changing a variables type at runtime?
- by james-west
Hi
I'm trying to create an object Of a specific type. I've got the following code, but it fails because it can't cast the new table object to the one that is already defined. I need table to start of an IEnumerable type so I can't declare is an object.
Public sub getTable(ByVal t as Type)
Dim table As Table(Of Object)
Dim tableType As Type = GetType(Table(Of )).MakeGenericType(t)
table = FormatterServices.GetUninitializedObject(tableType)
End sub
So in short - is there a way of changing a variable type at runtime? (or a better way of doing what I'm doing)
Thanks in advance.
James