I have the following definitions:
public class BaseEntity
{
...
public BaseEntity()
{
}
}
public class KeyValuePair
{
public string key;
public string value;
public string meta;
}
public class KeyValuePairList : BaseEntity
{
public List<KeyValuePair> List {set; get;}
public KeyValuePairList(IEnumerable<KeyValuePair> list)
{
this.List = new List<KeyValuePair>();
foreach (KeyValuePair k in list) {
this.List.Add(k);
}
}
}
I have 10 more different classes like KeyValuePair and KeyValuePairList all achieving the same purpose - the former defines the object, the latter defines the list into which these objects should be placed. How can I incorporate this functionality into the base class BaseEntity so that I don't have to redefine the List instantiation logic in each individual class i.e. I want to be able to instantiate the list based on the object type being passed to the constructor? Any suggestions?
BaseEntityclass defined within theBaseEntityclass? I don't think that's even possible. EDIT I think you meant that to be the constructor, right?classand you get a constructor.