I have a function that returns an array of objects. The problem is, the objects can be one of three different types. I am trying to break these objects into arrays of the different custom types.
For example:
var collection = something.ReturnObjArray();
var Details = collection.Where(a => a is DetailItem);
var Addenda = collection.Where(a => a is AddendaItem);
If i do the above and try to access the data in a foreach loop to put the Addenda in a collection within the Detail Items:
foreach (var addendaItem in Addenda)
{
var detailItem = Details.Single(d => d.DetailAddendaKey == addendaItem.Key);
detailItem.Addenda.Add(addendaItem);
}
I get errors like :
'object' does not contain a definition for 'DetailAddendaKey' and no extension method 'DetailAddendaKey' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Among others. If i try and change the var for Details and Addenda to:
IEnumerable<DetailItem> Details = collection.Where(a => a is DetailItem);
IEnumerable<AddendaItem> Addenda = collection.Where(a => a is AddendaItem);
I get past the error above, but now get:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<object>'
to 'System.Collections.Generic.IEnumerable<MyNameSpace.DetailItem>'
. An explicit conversion exists (are you missing a cast?)
Any ideas what I need to do?