This question is directly related to the protobuf-net supporter, but someone else will comment.
I tried to serialize a class that contains a property that has an interface type, i.e.
[DataContract] public class SampleDataClass { [DataMember(Order=1)] public int Field1 { get; set; } [DataMember(Order = 2)] public IPayload Payload { get; set; } } [ProtoContract] [ProtoInclude(1, typeof(Payload))] public interface IPayload { int Field4 { get; set; } } [DataContract] public class Payload : IPayload { [DataMember(Order = 1)] public int Field4 { get; set; } }
I managed to get this to work by changing the source of v1 protobuf-net. I did not see any problems with this approach while ProtoInclude is defined for the interface.
It is clear that for compilation I had to allow ProtoContract and ProtoInclude for design on interfaces, as well as several other changes here and there. (note, I would use DataContract / KnownType, but these attributes also cannot be decorated on interfaces)
Could you comment on possible flaws?
source share