我目前正在尝试将网络应用中的searchList从列表转换为数组,以便可以在Web方法中使用它。现在,我使用的Web引用只允许传递和返回数组。我只想简单地将列表转换为数组,但看起来它不会起作用。我尝试过在线查看,但我发现的每个场景都不足以解决这个问题。有关最佳方法的任何想法吗?
网络应用
Protected Function SearchCustomer()
Dim searchList As List(Of prxCustomerWebService1.Customer)
Dim objCustomerWS As New prxCustomerWebService1.CustomerWS
searchList = Cache("CustomerData")
'arr = searchList.ToArray
If (ddlSearchSpecs.Text = "Contains") Then
searchList = objCustomerWS.GetContains(tbSearch.Text, ddlSearchFields.Text, searchList)
ElseIf (ddlSearchSpecs.Text = "Starts With") Then
searchList = objCustomerWS.GetStartsWith(tbSearch.Text, ddlSearchFields.Text, searchList)
Else
searchList = objCustomerWS.GetExact(tbSearch.Text, ddlSearchFields.Text, searchList)
End If
If searchList.Count = 0 Then
lMessage.Text = "No Customers Found"
End If
Return searchList
End Function
网络方法
<WebMethod(description:="Gets customers that contain a specific value")> _
Public Function GetContains(ByVal sStringContains As String, ByVal sPropertyName As String, ByVal oListOfCustomers List(Of Customer))
oListOfCustomers()
Return CustomerFactory.GetContains(sStringContains, sPropertyName, oListOfCustomers)
End Function
逻辑
Public Shared Function GetContains(ByVal sStringContains As String, ByVal sPropertyName As String, ByVal oListOfCustomers As List(Of Customer))
Dim oCustomerData As New CustomerData
Dim oNewListOfCustomers As New List(Of Customer)
Dim iIndex As Integer
Dim propertyInfo As PropertyInfo
propertyInfo = GetType(Customer).GetProperty(sPropertyName)
If IsNothing(oListOfCustomers) = False AndAlso oListOfCustomers.Count > 0 Then
Try
For iIndex = 0 To oListOfCustomers.Count - 1
If (propertyInfo.GetValue(oListOfCustomers.Item(iIndex)).ToString.Trim.ToLower.Contains(sStringContains.ToLower) = True) Then
oNewListOfCustomers.Add(oListOfCustomers.Item(iIndex))
End If
Next
Catch ex As Exception
Return True
End Try
End If
Return oNewListOfCustomers
End Function