Does protobuf-net support nullable types?

前端 未结 3 1437
盖世英雄少女心
盖世英雄少女心 2021-01-04 02:31

Is it possible to generate nullable members in protobuf-net?

message ProtoBuf1 {
    optional Int32? databit = 1;
    optional Nullable databool          


        
3条回答
  •  醉梦人生
    2021-01-04 02:55

    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.

提交回复
热议问题