c# reflection - getting the first item out of a reflected collection without casting to specific col
- by Andy Clarke
Hi,
I've got a Customer object with a Collection of CustomerContacts
IEnumerable Contacts { get; set; }
In some other code I'm using Reflection and have the PropertyInfo of Contacts property
var contacts = propertyInfo.GetValue(customerObject, null);
I know contacts has at least one object in it, but how do I get it out? I don't want to Cast it to IEnumerable because I want to keep my reflection method dynamic. I thought about calling FirstOrDefault() by reflection - but can't do that easily because its an extension method.
Does anyone have any ideas?
Thanks