I am trying to make a dictionary of lists of derived objects. My solution was to use classes for each object that implemented the same base interface. The issue is that interface must have the property of the list of the object its designated to contain. That property must allow me to store each one of the derived classes without data loss from the objects.
I've tried down casting the lists and putting them straight into the dictionaries. I've tried making wrapper classes and down casting the base property to the proper list also.
public class Body
{
Dictionary<string, List<BodyPart>> parts;
public Body(List<Arms> arms_, List<Head> head_) //etc
{
parts = new Dictionary<string, List<BodyPart>>()
{
{"arms", arms_},
{"head", head_}
//etc
}
}
}
problem with this solution is that the lists of specific derived body parts will not cast to a list of the base class BodyPart. The other issue is that I'm also certain that because this is down casting it will cause data loss as I will only be able to reference the objects as the base class.
I expect the result to be a dictionary of different body parts that I can reference without data loss.