2
votes

Protobuf-net has an option to serialize public fields of the class

[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public class Customer
{

}

To enable ProtoBuf to work for most DTOs I had to add this attribute to each class. Is there a way to set it globally, so if class being serialized doesn't have any attributes like ProtoContract or DataContract, it will use "ImplicitFields.AllPublic" by default?

1
You can dom some Aspect oriented programming :-). and Inject the attribute to all public fields.MBen

1 Answers

2
votes

No, that isn't currently supported. In v2, you can, however, tell it about types at runtime, via

RuntimeTypeModel.Default.Add(typeof(Customer), false).Add({fields});

but there isn't currently an option from there that accepts ImplicitFields (this is just an oversight, and will be added in a future build).

I have also had discussion with a few people about adding an event that is triggered the first time a new type is seen, that would allow you to do this by subscribing to an event. That has yet to be written, though.