0

Is it possible to check if an object (for instance a DataGridView.DataSource) is a List(Of T) without specifying the T?

For example, I know that I can do:

If TypeOf(DataGridview.DataSource) Is List(Of Order) Then
    ...
End If

However, I do not want to check for each possibility (there are hundreds). I have code already to do the dynamic sorting based on column name (which, per standards, will always map to a property name within the List(Of T)), but need to check that the DataSource is a List and not, say, a DataTable, first.

Dave Johnson
  • 825
  • 16
  • 27
  • http://stackoverflow.com/questions/794198/how-do-i-check-if-a-given-value-is-a-generic-list – Marc Apr 24 '15 at 14:57
  • @Marc fantastic. Never been so happy to have posted a duplicate question. – Dave Johnson Apr 24 '15 at 14:58
  • Why don't you just check whether the property is available? That's what you *really* want to know. Use dgv.DataSource.GetType().GetProperty("foo") or dgv.Columns(ix).Name – Hans Passant Apr 24 '15 at 15:00

0 Answers0