The title may seem a bit confusing, so let me explain.
I am using Json.Net and XNA.
I have an entity class, that has a virtual update method. I also have a class named Monster
, which inherits the entity method. It also overrides the update method, making the entity move.
So since I'm serializing a list of entities, and when I deserialize them, they are changed back into a regular Entity
class. So how would I go about deserializing them back into their appropriate type?
A little more of an explanation, if you still find it a bit confusing, this time in code:
List<Entity entityList = new List<Entity>();
// Create a new monster (that inherits/derives entity)
Monster monster = new Monster(new Vector2(100, 100));
// Add it to our list of entities
entityList.Add(monster);
// Serialize the list of entities
string json = JsonConvert.SerializeObject(entityList);
// Now restore the entity list from the json
entityList = JsonConvert.DeserializeObject<List<Entity>>(json);
// ^ After the list has been restored, the original monster entity has been changed
// into a normal entity and will not do anything. How would I go about saving the type?