"Joerg Battermann" <jb@justbe.com> schrieb:
thanks for the quick reply, however is it possible to define a name in
your example using the Predicate(Of Person)(AddressOf GetFrank)?
I am calling a function with an IDNumber as variable and it shall find me
the one Requirement that has that particular IDNumber... and return it or
do something with it
I didn't have enough time to play around with this, but maybe the solution
below will help you solve the problem (quick and dirty!):
\\\
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As New List(Of Person)
x.Add(New Person("Peter", 1099))
x.Add(New Person("Frank", 342234))
x.Add(New Person("Fergus", 23423))
x.Add(New Person("Bill", 234))
Dim p As Person = (New PersonFinder()).Find(x, "Frank")
MsgBox(p.Name)
End Sub
End Class
Public Class PersonFinder
Inherits Finder(Of Person)
Protected Overrides Function InternalFind(ByVal obj As Person) As
Boolean
Return obj.Name = DirectCast(Parameters(0), String)
End Function
End Class
Public Class Person
Public Sub New(ByVal Name As String, ByVal Salary As Double)
Me.Name = Name
Me.Salary = Salary
End Sub
Public Name As String
Public Salary As Double
End Class
Public MustInherit Class Finder(Of T)
Private m_Parameters() As Object
Protected Property Parameters() As Object()
Get
Return m_Parameters
End Get
Private Set(ByVal Value As Object())
m_Parameters = Value
End Set
End Property
Public Function Find( _
ByVal List As List(Of T), _
ByVal ParamArray Parameters() As Object _
) As T
Me.Parameters = Parameters
Return List.Find(AddressOf InternalFind)
End Function
Protected Overridable Function InternalFind( _
ByVal obj As T _
) As Boolean
'
End Function
End Class
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>