Given a generic list of type List<T> , how to find type T ?
I assume that if the list is full, I could take listInstance[0].GetType() , but that seems a bit hacky.
Edit:
In context, I want to populate a DataTable with columns based on the properties of an object. If the property of the object is a general list, I want to add a column for each property of the object stored in the list. I will smooth the data structure to fit into the DataRow later.
The reason I don't want to use the type of the first object in the list is because it does not guarantee that each instance will have a populated list. Some will, and some won't, but I still need all the columns.
source share