这是一个名为Windows 8 隔离存储的库,它使用 XML 序列化。您可以存储object
以及List<T>
. 使用也非常简单。只需在您的项目中添加 DLL,您就有了存储数据的方法。
public class Account
{
public string Name { get; set; }
public string Surname{ get; set; }
public int Age { get; set; }
}
保存在隔离存储中:
Account obj = new Account{ Name = "Mario ", Surname = "Rossi", Age = 36 };
var storage = new Setting<Account>();
storage.SaveAsync("data", obj);
从隔离存储加载:
public async void LoadData()
{
var storage = new Setting<Account>();
Account obj = await storage.LoadAsync("data");
}
此外,如果您想存储列表:将列表保存在独立存储中:
List<Account> accountList = new List<Account>();
accountList.Add(new Account(){ Name = "Mario", Surname = "Rossi", Age = 36 });
accountList.Add(new Account(){ Name = "Marco", Surname = "Casagrande", Age = 24});
accountList.Add(new Account(){ Name = "Andrea", Surname = "Bianchi", Age = 43 });
var storage = new Setting<List<Account>>();
storage.SaveAsync("data", accountList );
从独立存储中加载列表:
public async void LoadData()
{
var storage = new Setting<List<Account>>();
List<Account> accountList = await storage.LoadAsync("data");
}