Je suis en train d'obtenir mon code de travail selon l'instruction sur http://www.paulstovell.com/vb-anonymous-methodsEssayer de faire fonctionner les méthodes anonymes VB. listes d'interrogation
Jusqu'à présent, j'ai l'emballage:
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
J'ai la fonction que j'ai modifié pour utiliser mon identifiant du département variable (a fait)
Function DidMatch(ByVal item As ListDataItem, ByVal did As Integer) As Boolean
Return item.AssigneddepartmentID.Equals(did)
End Function
Alors j'essaie de l'appeler de mon code:
Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of Integer, Integer)(Did, AddressOf DidMatch))
Puis j'obtiens une erreur sur DidMatch ... Erreur Méthode 'Fonction publique DidMatch (item As DeptMenuData, fait en tant qu'entier) Comme booléen' n'a pas de signature compatible avec le délégué 'Fonction de délégation PredicateWrapperDelegate (Of Integer, Integer) (item As Integer, argument As Integer) Comme booléen '.
Pouvez-vous voir ce que je fais mal?
Merci.