Trabajando en una aplicación que me permite sincronizar información con uno de mis clientes me tope con la necesidad de transformar un IList que era entregado por el cliente a un DataTable.
Asi quedo todo:
Public Shared Function IList_DataTable(Of T)(ByVal list As IList(Of T)) As DataTable
Dim td As New DataTable
Dim entityType As Type = GetType(T)
Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(entityType)For Each prop As PropertyDescriptor In properties
td.Columns.Add(prop.Name)
NextFor Each item As T In list
Dim row As DataRow = td.NewRow()For Each prop As PropertyDescriptor In properties
row(prop.Name) = prop.GetValue(item)
Nexttd.Rows.Add(row)
NextReturn table
End Function