消耗经典ASP返回LIST(类型).NET函数的结果 [英] Consume Result of .NET Function Returning LIST(Of Type) in Classic ASP

查看:434
本文介绍了消耗经典ASP返回LIST(类型).NET函数的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下以下VB.NET类:

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

现在我们有以下经典ASP页:

Now we have the following Classic ASP Page:

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

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

如何使用retList?我试图通过循环使用2以下方法:

How do you use retList? I have tried looping through using the 2 following methods:

1. For Each Person in retList  

抛出错误对象不是集合

Throws error "Object not a collection"

2. For i = 0 To Ubound(retList)

抛出错误类型不匹配:-UBound -

Throws error "Type mismatch: -UBound-

在此先感谢您的帮助。
杰克

Thanks in advance for your help. Jake

更新

UPDATE

从克里斯·哈斯我们能够解决问题的帮助为主。它确实需要第二个ASPClassic辅助函数来(的T)的列表转换为一个对象数组;然而,COM对象可以不公开的通用方法。由于这个原因,输入必须是一个特定类型的列表的要转换为对象阵列。解决方案在

Based on help from Chris Haas we were able to solve the issue. It does require a second ASPClassic helper function to convert the List(of T) to an Object array; however, COM objects cannot expose generic methods. Because of this, the input must be a specific type of List to be converted to the 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

感谢您克里斯哈斯的把我在正确的方向。
希望这可以帮助别人。

Thank you to Chris Haas for putting me on the right direction. Hope this helps someone else.

推荐答案

我不认为你将能够使用泛型与ASP经典,我想你会需要将其转换为一个数组。你可以写ASP经典使用一个实用方法,它接受的IList(Of T)已并返回对象() 。其ASP经典的人一个额外的步骤,以通过跳跃,但不是世界的尽头。

I don't think you're going to be able to use generics with ASP Classic, I think you're going to need to convert it to an array. You could write a utility method for ASP Classic usage that takes a IList(Of T) and returns an Object(). Its an extra step for ASP Classic people to jump through but not the end of the world.

修改

这样的事情可能做的伎俩:

Something like this might do the trick:

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

编辑2

下面是另一个只返回一个对象,pretty难看,但应该仍然工作的版本。

Here's another version that returns just an object, pretty ugly but should still work.

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

这篇关于消耗经典ASP返回LIST(类型).NET函数的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆