It supports several templates here to help migrate from other serializers. Note that in protobuf-net protogen there are options to enable these elements for you automatically.
First, nothing is null ; this includes both null references and Nullable<T> for structures. So:
[ProtoMember(1)] public int? A {get;set;}
will behave.
Another option is the default values; using .NET conventions:
[ProtoMember(2), DefaultValue(17)] public int B {get;set;}
no 17 values ββwill be serialized.
For more explicit control, the ShouldSerialize* pattern (from XmlSerializer ) and the *Specified pattern (from DataContractSerializer ) are observed, so you can do:
[ProtoMember(3)] public string C {get;set;} public bool ShouldSerializeC() { }
and
[ProtoMember(4)] public string D {get;set;} public bool DSpecified {get;set;}
They can be public or private (unless you create a separate serialization assembly that requires public access).
If your main classes come from gen code, then the partial class is the ideal extension point, i.e.
partial class SomeType { }
as you can add this to a separate code file.
source share