尝试让 VB 匿名方法正常工作。查询列表

发布于 2024-09-08 10:42:44 字数 1620 浏览 10 评论 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(item As DeptMenuData, did As Integer) As Boolean”没有与委托兼容的签名“委托函数 PredicateWrapperDelegate(Of Integer, Integer)(item As Integer, argument As Integer)”作为布尔值'。

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

谢谢。

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
        Return 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弱骨蛰伏 2024-09-15 10:42:44

更改:

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))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文