ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

GetList(of TList)

Return object of Subclass of List(Of T) using FindAll method of List.

Source

<Extension()> _
Public Function GetList(Of TList As {IList(Of T), New}, T)(ByVal items As List(Of T)) As TList

    Dim ReturnList As New TList

    For Each item As T In items
        ReturnList.Add(item)
    Next
    Return ReturnList
End Function

Example

Public Class AddressList
     Inherits System.Collection.Generic.List(of Address)
     ........
End Class

Public Class Address
     .........
End Class

Function GetAddressByType(Byval AddressType As String) As AddressList
Return AllAddresses.FindAll(Function(A As Address) A.App_Address_Type = AddressType).GetList(Of AddressList)()
End Function

Author: NetDorkie

Submitted on: 16 jul. 2009

Language: VB

Type: System.Collection.Generic.List

Views: 4947