I would like to write a generic function that would search a List(Of T) for all elements of type TFilter and return a List(Of TFilter) which comprises those elements. I’ve tried this:
Public Function FilterList(Of T, TFilter)(ByVal ListToFilter As List(Of T)) As List(Of TFilter)
Return ListToFilter.FindAll(Function(z) z.GetType.Equals(GetType(TFilter))).ConvertAll(New Converter(Of T, TFilter)(Function(z) CType(z, TFilter)))
End Function
But, it gives the following error:
Value of type ‘T’ cannot be converted
to ‘TFilter’.
Is there any way to do this or am I SOL?
Thanks in advance
You need to constrain
TFilterto inheritT: