private static PropertyDescriptorCollection GetListItemPropertiesByType(Type type, PropertyDescriptor[] listAccessors, int startIndex) {
PropertyDescriptorCollection pdc = null;
Type subType = listAccessors[startIndex].PropertyType;
// subType is the property type - which is not to be confused with the item type.
// For example, if a class Customer has a property of type Orders[], then Given:
// GetListItemProperties(typeof(Customer), PDForOrders)
// PDForOrders.PropertyType will be Array (not Orders)
//
// If there are no more ListAccessors, then we want:
// GetListItemProperties(PDForOrders.PropertyType) // this returns the shape of Orders not Array
// If there are more listAccessors, then we'll call
// GetListItemProperties(PDForOrders.PropertyType, listAccessors, startIndex++)
startIndex = startIndex + 1;
if (startIndex >= listAccessors.Length) {
// Last item, return shape of item
pdc = GetListItemProperties(subType);
}
else {
// Walk down the tree
pdc = GetListItemPropertiesByType(subType, listAccessors, startIndex);
}
// Return descriptors
return pdc;
}