IList и SortableBindingList

Можно ли создать сортируемый список в общем виде из IList?

я имею

Private Class DTO
        Public Property text1 As Integer
        Public Property text2 As String
        Public Property text3 As String
        Public Property text4 As DateTime
    End Class

    Private Function getList() As List(Of DTO)
        Dim l As New List(Of DTO)
        l.Add(New DTO With {.text1 = 1, .text2 = Nothing})
        l.Add(New DTO With {.text1 = 2, .text2 = "xxx"})
        l.Add(New DTO With {.text1 = 3, .text2 = "yyy"})

        For i = 1 To 2000
            l.Add(New DTO With {.text1 = i, .text2 = "a_" & (2000 - i).ToString, .text3 = "test" & i, .text4 = DateTime.Now})
        Next
        Return l
    End Function

 Private Sub fillListSearch(Of T)(lst As SortableBindingList(Of T))
        fillWithList(lst)
    End Sub

    Private Sub fillWithList(ByRef pr_list As IList)
        '--> create a SortableBindingList of this list
        grd.DataSource = pr_list
    End Sub

Мне нужно переместить функциональность из fillListSearch в орех fillWithList, я не понимаю, как преобразовать этот IList в SortableBindingList(Of T).

Есть намеки? Можно ли это сделать с помощью отражения?

_Спасибо

Обновление: удалось получить это работает

Private Sub fillWithList(ByRef pr_list As IList)


     Dim tList As System.Type = pr_list.GetType()
            Dim typeIntern = tList.GetGenericArguments()(0)
            Dim typeSortList As Type = GetType(SortableBindingList(Of ))
            Dim typeArgs() As Type = {typeIntern}
            Dim constructed As Type = typeSortList.MakeGenericType(typeArgs)
            Dim sortedList As Object = Activator.CreateInstance(constructed, pr_list) 
            grd.DataSource = sortedList 

0 ответов

Другие вопросы по тегам