I want to filter objects in a List<ISeries> using their type using OfType <>. . My problem is that some objects have a common interface type, but they do not have a common inherited interface.
I have the following definitions:
public interface ISeries public interface ITraceSeries<T> : ISeries public interface ITimedSeries : ISeries //and some more...
My list contains all ISeries types, but now I want to get only those ITraceSeries objects, regardless of their actual typical type parameter, for example:
var filteredList = myList.OfType<ITraceSeries<?>>(); //invalid argument!
How can i do this?
An unfavorable solution would be to introduce the ITraceSeries type, which inherits from ISeries :
public interface ITraceSeries<T> : ITraceSeries
Then use ITraceSeries as a filter. But in reality, this does not add new information, but only makes the inheritance chain more complex.
It seems to me that this is a common problem, but I did not find useful information about SO or on the Internet. Thanks for the help!
source share