G
Guest
We have a class that has a public property that is of type List<T>. FXCop
generates a DoNotExposeGenericLists error, indicating
"System.Collections.Generic.List<T> is a generic collection designed for
performance not inheritance and, therefore, does not contain any virtual
members. The following generic collections are designed for inheritance and
should be exposed instead of System.Collections.Generic.List<T>.
* System.Collections.ObjectModel.Collection<T>
* System.Collections.ObjectModel.ReadOnlyCollection<T>
* System.Collections.ObjectModel.KeyedCollection<TKey, TItem> "
Our property is not "virtual" and thus cannot be overridden. We used
List<T> becasue we wanted a generic array. A collection is unordered and
thus not as good a match, even if it is better designed for inheritance.
Can anyone explain in more depth why having a non-virtual, List<t> property
is bad? Why should I care is List<T> has any virtual members when I am
simply using an instance of and _not_ inheriting from List<T>?
Thanks,
--BJ
generates a DoNotExposeGenericLists error, indicating
"System.Collections.Generic.List<T> is a generic collection designed for
performance not inheritance and, therefore, does not contain any virtual
members. The following generic collections are designed for inheritance and
should be exposed instead of System.Collections.Generic.List<T>.
* System.Collections.ObjectModel.Collection<T>
* System.Collections.ObjectModel.ReadOnlyCollection<T>
* System.Collections.ObjectModel.KeyedCollection<TKey, TItem> "
Our property is not "virtual" and thus cannot be overridden. We used
List<T> becasue we wanted a generic array. A collection is unordered and
thus not as good a match, even if it is better designed for inheritance.
Can anyone explain in more depth why having a non-virtual, List<t> property
is bad? Why should I care is List<T> has any virtual members when I am
simply using an instance of and _not_ inheriting from List<T>?
Thanks,
--BJ