在 WP7 中的独立存储中存储类对象 [英] Storing class object in Isolated Storage in WP7

查看:24
本文介绍了在 WP7 中的独立存储中存储类对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 WP7 独立存储中存储类的对象?我想检索它并在需要时进行编辑.

How can I store object of a class in WP7 Isolated Storage? I want to retrieve it and edit it whenever required.

推荐答案

你需要序列化你的数据来保存它,然后反序列化它来加载它.您可以在本文中找到完整的示例.

You need to serialize your data to save it, then deserialize it to load it. You can find a complete worked example in this article.

例如标记类和属性如下:

For example, mark the class and properties as follows:

[DataContract] 
public class Employee  
{  
     [DataMember] 
     public int EmployeeNumber { get; set; }  
     [DataMember] 
     public string Name { get; set; }  
     [DataMember] 
     public string Department { get; set; }  
}

构造一个序列化器:

DataContractSerializer mySerializer = new DataContractSerializer(typeof(Employee)); 

然后通过ReadObject/WriteObject加载/保存.

Then load / save via ReadObject / WriteObject.

这篇关于在 WP7 中的独立存储中存储类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆