请问protobuf网的支持可空类型? [英] Does protobuf-net support nullable types?
本文介绍了请问protobuf网的支持可空类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能产生protobuf网?
消息ProtoBuf1 {
可选的Int32成员可为空?数据位= 1;
可选可空<布尔> databool = 2;
}
解决方案
是的,但它不 ŧ的如果你正在做的.proto CODEGEN默认生成的他们。
如果这仅仅是C#,当然,你不需要 .proto - 只是:
[ProtoContract]
公共类ProgoBuf1
{
[ProtoMember(1)]
公众诠释?富{获取;设置;}
[ProtoMember(2)]
公众持股量?酒吧{获取;集;}
}
如果您的是从.proto工作,你可以考虑复制和编辑 csharp.xslt
来满足您的首选布局。
Is it possible to generate nullable members in protobuf-net?
message ProtoBuf1 {
optional Int32? databit = 1;
optional Nullable<bool> databool = 2;
}
解决方案
Yes, but it doesn't generate them by default if you are doing codegen from .proto.
If this is just C#, of course, you don't need a .proto - just:
[ProtoContract]
public class ProgoBuf1
{
[ProtoMember(1)]
public int? Foo {get;set;}
[ProtoMember(2)]
public float? Bar {get;set;}
}
If you are working from .proto, you could consider copying and editing csharp.xslt
to suit your preferred layout.
这篇关于请问protobuf网的支持可空类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文