I have a private class variable that holds a collection of order items:
Private _Items As New System.Collections.Generic.SortedList(Of Integer, OrderItem)
What I’m trying to do it Get and Set a subset of the items through a Property on the class using the .Where() extension method of IEnumerable (I think). Something along the lines of:
Public Property StandardItems() As SortedList(Of Integer, OrderItem)
Get
Return _Items.Where(Function(ItemID As Integer, Item As OrderItem) Item.ItemType = "SomeValue")
End Get
Set(ByVal value As SortedList(Of Integer, OrderItem))
_Items = value
End Set
End Property
Is this possible? If so, how would I implement it? I’m not having much luck with MSDN docs, Visual Studio intellisense or trial and error.
The
Whereextension method returns anIEnumerable(Of KeyValuePair(Of Integer, OrderItem)). You can change the type of your property to it.If you need to return a sorted list, you’ll have to create that manually from the output of
Wheremethod:I’m a little worried about how your setter behave. Do you want to replace your whole sorted list through the property? It’s name says it’s just standard items (a filtered set of items) but setting it would change all items.