Here are two ways I came across to resolve your issue. One way uses LINQ query syntax to filter; the second uses a custom object to store your predicate parameters, and then uses this object to execute the filter.
Using LINQ syntax in the Item property:
Default Public Overridable Shadows ReadOnly Property Item(ByVal x As String, ByVal y As Integer, ByVal z As String) As IEnumerable(Of A)
Get
Return (From theA In Me
Where (theA.x = x And theA.y = y And theA.z = z)
Select theA)
End Get
End Property
- PredicateParameter , , . MSDN - . :
Class PredicateParams
Public Sub New(ByVal theA As A)
Criteria = theA
End Sub
Public Property Criteria As A
Public Function IsMatch(ByVal theA As A) As Boolean
Return (theA.x = Criteria.x And theA.y = Criteria.y And theA.z = Criteria.z)
End Function
End Class
, CollOfA, :
Public Overridable Shadows ReadOnly Property ItemPred(ByVal x As String, ByVal y As Integer, ByVal z As String) As IEnumerable(Of A)
Get
Dim predA As New A
predA.x = x
predA.y = y
predA.z = z
Dim pred As New PredicateParams(predA)
Return Me.FindAll(AddressOf pred.IsMatch)
End Get
End Property
, , .
Sub Main()
Dim mycoll As New CollOfA()
For index = 1 To 100
Dim anA As New A()
anA.x = (index Mod 2).ToString()
anA.y = index Mod 4
anA.z = (index Mod 3).ToString()
mycoll.Add(anA)
Next
Dim matched As IEnumerable(Of A) = mycoll.Item("1", 3, "2")
Dim matched2 As IEnumerable(Of A) = mycoll.ItemPred("1", 3, "2")
Console.WriteLine(matched.Count.ToString()) 'output from first search
Console.WriteLine(matched2.Count.ToString()) 'output from second search (s/b same)
Console.ReadLine()
End Sub
, . , . (, #, VB.NET .)