In protobuf-net, you can override the wire format for enumerations using ProtoEnumAttribute as follows:
[ProtoContract] enum MyEnum { [ProtoEnum(Value=1)] Default, [ProtoEnum(Value=10)] Foo }
With these attributes, where Default will usually serialize to 0 and Foo to 1 , they will now serialize to 1 and 10 respectively.
What I'm trying to do is to imitate this behavior using interfaces in ProtoBuf.Meta , so I don't need to comment on the enumerations (because I usually don't control them in my project).
Digging through the protobuf-net source, I managed to get the following (simplified) action:
var model = RuntimeTypeModel.Create(); var meta = model.Add(enumType, applyDefaultBehaviour: true); var fields = meta.GetFields();
However, I cannot send this, relying on a reflection in a private (read-only!) Field that just requires trouble.
So, is there a way to override enumeration posting values ββat runtime in protobuf-net?
source share