【发布时间】:2014-12-04 03:57:09
【问题描述】:
[Serializable]
class DOThis
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Value
{
get
{
if (_name == "Hi")
return "Hey Hi";
else
return "Sorry I dont know you";
}
}
}
我有上面的类要使用 BinaryFormatter 进行序列化。下面是序列化代码,
DOThis obj = new DOThis();
obj.Name = "Ho";
BinaryFormatter bfm = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bfm.Serialize(ms, obj);
如何在序列化和反序列化中忽略属性“值”,因为我总是可以使用“名称”属性检索“值”属性?
【问题讨论】:
-
不是直接回答你的问题,但你考虑过protobuf吗?我注意到在我的性能测试中,protobuf 比 BinaryFormatter 快 方式。
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
标签: c# serialization binaryformatter