I'm looking for a generic class adapter that would enable me to iterate over a collection of collection (IEnumerable of IEnumerable) of objects through a single iterator.
In other words: How to fake a collection of collection by let it appears to the user as one single flat collection.
Example: For a structure like this:
public class Signal
{
Point[] points;
}
public class Analysis
{
List<Signal> Signals;
}
I would like to have a generic adapter that enable me to iterate over each point of an Analysis object.
The adapter would enable me to do:
var analysisInnerCollectionOfPointAdapter =
new GenericCollectionOfCollectionAdapterIterator(myAnalysis);
foreach(Point point in AnalysisInnerCollectionOfPointAdapter)
{
...
}
I do not want to create any duplicate collection. I just want to make abstraction of the inner step (collection of collection) from my iteration.
I just start try to program it but I wonder if there is not something that already exists that would probably be better than my potential future creation. Perhaps in an existing library like Linq or MoreLinq? Perhaps you already done it and have something nice?
Edit (an hour after): I just found: Difference Between Select and SelectMany which give a good example of what I want. Thanks to AlexeiLevenkov.