The class I want to work with provides getters of type IEnumerable<X>and IEnumerable<Y>, where X and Y are subclasses of the base type T. I want to iterate over the contents of both the type in question and the type T. Is there a convenient way to combine both into something that 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 third line does not work:
'System.Collections.Generic.IEnumerable' does not contain a definition for 'Concat' and the best extension method is 'System.Linq.Enumerable.Concat (System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable)' has some invalid the arguments
Notice, I can’t change any of the source data, I need to create a new collection - in fact I want to make foreachit over it.
source
share