1

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 
4

0 に答える 0