I’ve tried to use .Find() methode and was successfully. But I can not understand how to work with FindAll to receive all items matching on a “flexible” keyword (in my case this keywords is called ClassGuid).
Public Class clsFindConnection
Private Delegate Function ConMatchDelegate(ByVal con As PropertyConnection, ByVal ClassGuid As String) As Boolean
Public Function GetPropertyConnectionsByGuid(ByVal ClassGuid As String, ByVal LBaseConnections As List(Of PropertyConnection)) As List(Of PropertyConnection)
Dim Res As List(Of PropertyConnection)
Dim dl As New ConMatchDelegate(AddressOf ConnectionFromMatch)
Res = LBaseConnections.FindAll(dl)'<-- ERROR. Can not work because delegate is only using a single item.
Return Res
End Function
Friend Function ConnectionFromMatch(ByVal con As PropertyConnection, ByVal ClassGuid As String) As Boolean
If con.PaintPluginFrom Is Nothing Then Return False
If con.PaintPluginFrom.Plugin Is Nothing Then Return False
If con.PaintPluginFrom.Plugin.Guid = ClassGuid Then Return True
Return False
End Function
End Class
How can this be used?
Use a lambda expression to pass the second parameter:
EDIT to answer your comment:
FindAlltakes aPredicate(Of T)(Predicate(Of PropertyConnection)in your case), so you can’t pass aConMatchDelegateto it, since the signature is not compatible. So I create aPredicate(Of PropertyConnection)using an anonymous method. This will probably be more understandable: