private static string GetListNameFromType(Type type) {
string name;
if (typeof(Array).IsAssignableFrom(type)) {
// If the type is Customers[], this will return "Customers"
name = type.GetElementType().Name;
}
else if (typeof(IList).IsAssignableFrom(type)) {
// If the type is BindingList<T>, TCollection, TList (or equiv), this will return "T"
PropertyInfo indexer = GetTypedIndexer(type);
if (indexer != null)
{
name = indexer.PropertyType.Name;
}
else
{
name = type.Name;
}
}
else {
// Fallback to type name
name = type.Name;
}
return name;
}