1 回答
TA贡献1770条经验 获得超3个赞
伪代码: 序列化:
using (var stream = File.Open(filePath, FileMode.Create))
{
var writer = new DataContractSerializer(myViewModelObject.GetType());
writer.WriteObject(stream, myViewModelObject);
stream.Close();
}
反序列化:
using (var fs = new FileStream(filePath, FileMode.Open))
{
var reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
var deserializer = new DataContractSerializer(MyViewModel);
var deserializedType = deserializer.ReadObject(reader, true);
reader.Close();
fs.Close();
return deserializedType;
}
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报