Consuming .NET Function Result Returning LIST (type) in Classic ASP

Imagine the following VB.NET class:

Public Class P
    Public Function GetDumbList() As List(Of DumbPeople)
        Dim retList As New List(Of DumbPeople)
        retList.Add Person1
        retList.Add Person2
        Return retList
    End Function
End Class

Now we have the following classic ASP page:

<%
Dim P
Set P = Server.CreateObject("Project.Assembly.Namespace.P")

retList = P.GetDumbList()
...
...
...
%>

How do you use retList? I tried to loop using the following two methods:

1. For Each Person in retList  

Throws an error "Object is not a collection"

2. For i = 0 To Ubound(retList)

Throws an error "Type mismatch: -More detail -

Thanks in advance for your help. Jake

UPDATE

Based on the help of Chris Haas, we were able to solve this problem. This requires a second helper function, ASPClassic, to convert List (of T) into an Object array; however, COM objects cannot expose common methods. Because of this, the input must be a specific type of list, which must be converted to an Object array. Solution below

Public Function DumbPeopleListToObjectArray(ByVal DPList As IList(Of DumbPeople)) As Object()
    Return Array.ConvertAll(Of DumbPeople, Object)(DPList.ToArray(), New Converter(Of DumbPeople, Object)(Function(j) DirectCast(j, Object)))
End Function

, . , - .

0
1

, generics ASP Classic, , . ASP Classic, IList(Of T) Object(). ASP Classic, , .

- :

Public Shared Function ToASPClassicArray(Of T)(ByVal myList As IList(Of T)) As T()
    Return myList.ToArray()
End Function

2

, , , .

Public Shared Function ToASPClassicArray(Of T)(ByVal myList As IList(Of T)) As Object()
    Return Array.ConvertAll(Of T, Object)(myList.ToArray(), New Converter(Of T, Object)(Function(j) DirectCast(j, Object)))
End Function
+3

All Articles