XML serialization :
ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
...
XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection<Customer>));
using (StreamWriter wr = new StreamWriter("customers.xml"))
{
xs.Serialize(wr, customers);
}
To reload the data from the file :
XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection<Customer>));
using (StreamReader rd = new StreamReader("customers.xml"))
{
customers = xs.Deserialize(rd) as ObservableCollection<Customer>;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…