我正在尝试将自定义类保存在 WP7 应用程序的独立存储中。
这是课程:
public class places
{
public GeoCoordinate coordonnees { get; set; }
public string nom { get; set; }
public places(GeoCoordinate coo, string _nom)
{
this.coordonnees = coo;
this.nom = _nom;
}
}
这是我正在尝试做的一个例子:
List<places> liste;
if (IsolatedStorageSettings.ApplicationSettings.Contains("places"))
{
liste = (List<places>)IsolatedStorageSettings.ApplicationSettings["places"];
} else {
liste = new List<places>();
}
liste.Add(new places(this.position_actuelle, this.name.Text));
IsolatedStorageSettings.ApplicationSettings["places"] = liste;
IsolatedStorageSettings.ApplicationSettings.Save();
我在 save() 方法上抛出了一个 InvalidDataContractException。
我知道我必须对我的班级进行序列化,但我还没有在谷歌上找到一个好的/简单的教程。
谢谢您的帮助。