A suggestion about NamedElementCollection<T>

Topics: General discussion
Jun 13, 2007 at 6:45 PM
I'd like to make a suggestion about class NamedElementCollection<T>.
Now it looks as:
public class NamedElementCollection<T> : ConfigurationElementCollection, IEnumerable<T>
where T : NamedConfigurationElement, new()
I think the constraint for generic parameter should be "ConfigurationElement, IObjectWithName", not "NamedConfigurationElement". This won't make me use class NamedConfigurationElement as base class for classes of collection elements.

For example, I have some collection:
public class MyCollectionData: NamedElementCollection<MyCollectionElementData> {}
I have to have MyCollectionElementData inherited from NamedConfigurationElement:
class MyCollectionElementData : NamedConfigurationElement {}
This makes me have 'name' attribute for collection element described by MyCollectionElementData:
<collectionelementtag name='...'/>
But I don't want to store 'name' attribute at all. In another case I don't want to use exactly name 'name' for it.

If we change the code for NamedElementCollection<T> on:
public class NamedElementCollection<T> : ConfigurationElementCollection, IEnumerable<T>
where T : ConfigurationElement, IObjectWithName, new()
I could choose identifing method for MyCollectionElementData:
class MyCollectionElementData: ConfigurationElement, IObjectWithName
public string Name
get { return <some calculating of unique name based on other attributes>; }

Sure you could say don't use NamedElementCollection<T> write your own analogue. Of cause I can.
But class NamedElementCollection<T> is widely used in EntLib. For example it's used as base class for cool PolymorphicConfigurationElementCollection<T>.

Thank you for attention.