protobuf-net enum serialization

前端 未结 2 879
南笙
南笙 2021-02-12 20:12

What needs to be done in order to serialize enums with protobuf-net? I\'m getting the below error when serializing a class having an enum property, if the DataMember attribute i

2条回答
  •  感动是毒
    2021-02-12 20:53

    Sample:

    [DataContract]
    [ProtoContract]
    public enum SiteType
    {
        [EnumMember]
        [ProtoEnum]
        Site = 1,
        [EnumMember]
        [ProtoEnum]
        Partition = 2,
        [EnumMember]
        [ProtoEnum]
        Module = 3
    }
    
    [DataContract]
    [Serializable]
    [ProtoContract]
    public class SiteDTO
    {
        [DataMember]
        [ProtoMember(1)]
        public int Id { get; set; }
        ...
        [DataMember]
        [ProtoMember(10)]
        public SiteType Type { get; set; }
    }
    

提交回复
热议问题