开发者

Trying to get VB anonymous methods working. querying lists

开发者 https://www.devze.com 2023-01-05 13:40 出处:网络
I am trying to get my code working as per the instruction on http://www.paulstovell.com/vb-anonymous-methods

I am trying to get my code working as per the instruction on http://www.paulstovell.com/vb-anonymous-methods

So far I have the wrapper:

Public Delegate Function PredicateWrapperDelegate(Of T, A)(ByVal item As T, ByVal argument As A) As Boolean
Public Class PredicateWrapper(Of T, A)
    Private _argument As A
    Private _wrapperDelegate As PredicateWrapperDelegate(Of T, A)

    Public Sub New(ByVal argument As A, _
         ByVal wrapperDelegate As PredicateWrapperDelegate(Of T, A))
        _argument = argument
        _wrapperDelegate = wrapperDelegate
    End Sub

    Private Function InnerPredicate(ByVal item As T) As Boolean
        Return _wrapperDelegate(item, _argument)
    End Function

    Public Shared Widening Operator CType( _
        ByVal wrapper As PredicateWrapper(Of T, A)) _
       As Predicate(Of T)
        Return New Predicate(Of T)(AddressOf wrapper.InnerPredicate)
    End Operator
End Class

Then I have the function which I have modified to use my department id variable (did)

 Function DidMatch(ByVal item As ListDataItem, ByVal did As Integer) As Boolean
        Re开发者_Python百科turn item.AssigneddepartmentID.Equals(did)
    End Function

Then I try to call it from my code:

Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of Integer, Integer)(Did, AddressOf DidMatch))

I then get an error on DidMatch ... Error Method 'Public Function DidMatch(item As DeptMenuData, did As Integer) As Boolean' does not have a signature compatible with delegate 'Delegate Function PredicateWrapperDelegate(Of Integer, Integer)(item As Integer, argument As Integer) As Boolean'.

Can you see what I am doing wrong?

Thanks.


Change:

Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of Integer, Integer)(Did, AddressOf DidMatch))

To:

Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of ListDataItem, Integer)(Did, AddressOf DidMatch))
0

精彩评论

暂无评论...
验证码 换一张
取 消