A class I want to operate on provides getters of type IEnumerable<X>
and IEnumerable<Y>
where X & Y are subclasses of base type T. I want to iterate over the contents of both treating them as type T. Is there a handy way to concatenate both into something which can be seen as IEnumerable<T>
?
Example:
IEnumerable<HeaderPart> headers = templateFile.MainDocumentPart.HeaderParts;
IEnumerable<FooterPart> footers = templateFile.MainDocumentPart.FooterParts;
List<OpenXmlPart> result = new List<OpenXmlPart>();
result.Concat<OpenXmlPart>(footers);
HeaderPart and FooterPart are both subclasses of OpenXmlPart but the 3rd line fails:
'System.Collections.Generic.IEnumerable' does not contain a definition for 'Concat' and the best extension method overload 'System.Linq.Enumerable.Concat(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable)' has some invalid arguments
Note, I can't change either of the source data, I need to create a new collection - actually I want to do a foreach
over it.