I recently made some code like this:
public class MenuItem
{
private List
public List
{
get { return _subItems;}
}
… …
}
This caused Code Analysis to throw a CA1002 warning – Do not expose generic lists.
(see ms help: http://msdn2.microsoft.com/en-us/library/ms182142(VS.90).aspx)
The help didn’t help much, but i solved it pretty simply by making a class that inherits the List generic class:
public class MenuItemCollection : List
{
}
public class MenuItem
{
private MenuItemCollection _subItems;
public MenuItemCollection SubItems
{
get { return _subItems;}
}
… …
}
This will avoid the CA1002 warning. Remember to name the collection class “Collection” in the end. Otherwise you will get a CA1710 warning, Identifies should have correct suffix. (http://msdn2.microsoft.com/en-us/library/ms182244(VS.90).aspx)
Leave a Reply