How should I serialize a list of actions (ie.
List<iAction> toDo;
) for saving to a file or sending over a LAN? I was going to use XmlSerializer, but I changed my List to include more than one type of action and now my plan doesn't work anymore.
Should I add a method to iAction such as iAction.Serialize and serialize each action instead of the whole list, or do I need to come up with something else? Btw, I'm using XmlSerializer because I want to save the list to an XML file for other reasons.
Here is what I was doing (simplified):
enum Shape { line, circle, square }
class Action
{
Point start;
Point stop;
Shape drawShape;
void Draw(Graphics gfx)
{
switch(drawShape)
}
}
void Main()
{
List<Action> toDo;
toDo.Add(Action);
toDo.Add(Action);
toDo.Add(Action);
XmlSerializer.Serialize(saveFile, toDo);
}
Now I have an action interface and different actions inheriting from it:
interface iAction
{
void Start(Point start);
void onMove(Point movedTo);
void Stop(Point stop);
void Draw(Graphics gfx);
}
class Line : iAction { ... }
class Path : iAction { ... }
class Square : iAction { ... }
...
void Main()
{
List<iAction> toDo;
toDo.Add(Line);
toDo.Add(Circle);
toDo.Add(Square);
XmlSerializer.Serialize(saveFile, toDo);
}