我正在尝试序列化List<T>
但得到空文件并且List<T>
不会序列化。我没有得到任何异常并阅读 protobuf-net 手册,我要序列化的所有成员都标有[ProtoContract]
和[ProtoMember]
属性
public void Save()
{
using (var outputStream = File.Create(SettingsModel.QueueListDataFile))
{
Serializer.Serialize(outputStream, QueueList);
}
}
[Serializable]
[ProtoContract]
public class QueueList : SafeList<QueueItem>
{
}
[Serializable]
[ProtoContract]
public class SafeList<T> : SafeLock
{
[ProtoMember(1)]
private static readonly List<T> ItemsList = new List<T>();
}
[Serializable]
[ProtoContract]
public class QueueItem
{
[ProtoMember(1)]
public string SessionId { get; set; }
[ProtoMember(2)]
public string Email { get; set; }
[ProtoMember(3)]
public string Ip { get; set; }
}