[ACCEPTED]-protobuf-net enum serialization-protobuf-net
Accepted answer
I suspect they are actually 2 different scenarios, but 11 with regard to the code sample added by 10 Andrew, this is because it can't figure 9 out (in advance) what it is going to do 8 with regards to default values (by default, data 7 is treated as optional at the receiver). There are 3 ways 6 of fixing this:
1: add an enum with value 5 0 (since 0 is always the CLI default value 4 for zeros), for example
public enum SiteType
{
Error = 0,
...
2: tell it which 3 value to use by default:
[ProtoMember(10), DefaultValue(SiteType.Partition)]
public SiteType Type { get; set; }
3: tell the engine 2 that it really doesn't need to worry about 1 it, i.e. that it is going to have a value:
[ProtoMember(10, IsRequired = true)]
public SiteType Type { get; set; }
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; }
}
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.