尝试让 VB 匿名方法正常工作。查询列表
我正在尝试让我的代码按照 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改:
至:
Change:
To: