Collections in the framework are defined in such a way that when enumerating their items, we end up with ... objects.
An example of that is the PropertyDescriptorCollection which (I am pretty sure of) will never contain anything else than a PropertyDescriptor but yet we are forced to cast or define the type explicitly.
Either those collections should be removed from the framework as they do not bring anything more than troubles, and return IEnumerable<T> would be more constructive; or they should implement the proper interfaces.
PropertyDescriptorCollection is defined as ICollection, IList, IDictionary, this does not make any sense, PropertyDescriptor does not appear anywhere.
Many collections in the framework are like that. I don't know whether this is a required pattern, but if it is, it is wrong.
PropertyDescriptorCollection should be ICollection<PropertyDescriptor> and when you enumerate it, you get PropertyDescriptor and not an object.
Originally posted by @Scal-Human in dotnet/sdk#55773
Collections in the framework are defined in such a way that when enumerating their items, we end up with ... objects.
An example of that is the
PropertyDescriptorCollectionwhich (I am pretty sure of) will never contain anything else than aPropertyDescriptorbut yet we are forced to cast or define the type explicitly.Either those collections should be removed from the framework as they do not bring anything more than troubles, and return
IEnumerable<T>would be more constructive; or they should implement the proper interfaces.PropertyDescriptorCollectionis defined asICollection,IList,IDictionary, this does not make any sense,PropertyDescriptordoes not appear anywhere.Many collections in the framework are like that. I don't know whether this is a required pattern, but if it is, it is wrong.
PropertyDescriptorCollectionshould beICollection<PropertyDescriptor>and when you enumerate it, you getPropertyDescriptorand not an object.Originally posted by @Scal-Human in dotnet/sdk#55773