0

我试图让我的代码按照http://www.paulstovell.com/vb-anonymous-methods上的说明工作

到目前为止,我有包装:

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

然后我有了修改后的函数以使用我的部门 id 变量 (did)

 Function DidMatch(ByVal item As ListDataItem, ByVal did As Integer) As Boolean
        Return item.AssigneddepartmentID.Equals(did)
    End Function

然后我尝试从我的代码中调用它:

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

然后我在 DidMatch 上收到一个错误...错误方法“公共函数 DidMatch(项目作为 DeptMenuData,作为整数)作为布尔值”没有与委托“委托函数 PredicateWrapperDelegate(整数,整数)(项目作为整数)兼容的签名, 参数 As Integer) As Boolean'。

你能看到我做错了什么吗?

谢谢。

4

1 回答 1

0

改变:

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

到:

Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of ListDataItem, Integer)(Did, AddressOf DidMatch))
于 2010-07-01T09:19:20.827 回答