[英]Serializing private members with protobuf-net for windows store apps
I'm trying to serialize a simple custom class that has private members, using protobuf-net library, for a windows store style app: 我正在尝试使用protobuf-net库为一个Windows商店风格应用序列化一个简单的自定义类,其中包含私有成员:
[ProtoContract]
class ProtoTest
{
[ProtoMember(1)]
string Test;
public ProtoTest(string test)
{
this.Test = test;
}
}
When I serialize an instance the private member is never serialized but is instead ignored. 当我序列化一个实例时,私有成员永远不会被序列化,而是被忽略。 Making the member public resolves the problem but is not really a satisfactory solution for my application.
让会员公开解决问题,但对我的应用程序来说并不是一个真正令人满意的解决方案。 Is there anything that I'm doing incorrectly here or does anybody know if this is a known bug (I did search but couldn't find anything)?
有什么我在这里做错了或有人知道这是一个已知的错误(我做了搜索但找不到任何东西)?
The sample in the protobuf-net wiki . protobuf-net wiki中的示例。
[ProtoContract]
public class StandaloneExtensible : IExtensible
{
[ProtoMember(1)]
public int KnownField { get; set; }
private byte[] buffer;
Stream IExtensible.BeginAppend() {
return Extensible.BeginAppend();
}
Stream IExtensible.BeginQuery() {
return Extensible.BeginQuery(buffer);
}
void IExtensible.EndAppend(Stream stream, bool commit) {
buffer = Extensible.EndAppend(buffer, stream, commit);
}
void IExtensible.EndQuery(Stream stream) {
Extensible.EndQuery(stream);
}
int IExtensible.GetLength() {
return Extensible.GetLength(buffer);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.