What is the best way to save a list of objects to an XML file and load that list back using C#?
- by Siracuse
I have a list of "Gesture" classes in my application:
List<Gesture> gestures = new List<Gesture>();
These gesture classes are pretty simple:
public class Gesture
{
public String Name { get; set; }
public List<Point> Points { get; set; }
public List<Point> TransformedPoints { get; set; }
public Gesture(List<Point> Points, String Name)
{
this.Points = new List<Point>(Points);
this.Name = Name;
}
}
I would like to allow the user to both save the current state of "gestures" to a file and also be able to load a file that contains the data of the gestures.
What is the standard way to do this in C#?
Should I use Serialization? Should I write a class to handle writing/reading this XML file by hand myself? Are there any other ways?