Inheritance Support in protobuf-net wiht WCF

326 views
Skip to first unread message

Bartosz Pierzchlewicz

unread,
Dec 10, 2009, 9:42:16 AM12/10/09
to Protocol Buffers
Hello,

I have two classes:

[DataContract]
public class TestClass: Base<TestClass>
{
[DataMember(Order = 1)]
public string Str { get; set; }
}

[DataContract]
[ProtoInclude(1,typeof(TestClass))]
public class Base<T>
{
[DataMember]
public T ReturnType { get; set; }
}

I know, that I must use ProtoInclude attribute to allow serialization.

Problem is, that I have about 100 classes that inherit from Base
class, and I should write 100 attributes.
Is any possibility to add this information not using Attribute on
class but programmatically?

In DataContractSerializerOperationBehavior when you override method
CreateSerializer you may write code to add your own list of known
types.

But.. ProtoInclude has not only information about type but also tag.


can anyone help?

Bartosz Pierzchlewicz

Marc Gravell

unread,
Dec 10, 2009, 2:32:06 PM12/10/09
to Bartosz Pierzchlewicz, Protocol Buffers
Hi Bartosz;

At the moment, it only supports the reflection/attribute based approach (directly comparably to the [KnownType] attribute used in vanilla WCF / DataContractSerializer). I have some plans and prototype code to rectify this (runtime models), but it is lots of work, and it isn't anything I can promise on any fixed timescale I'm afraid.

In order to shim inheritance into the protocol buffers format (without doing anything /too/ evil) it needs to know a unique tag per subclass. I can't help thinking that the most pragmatic option here is just to add a few attributes. Hunting for subclasses on the fly would be messy, and I can't include the type metadata without breaking completely from the standard protocol buffers wire format.

Marc Gravell
(protobuf-net)

2009/12/10 Bartosz Pierzchlewicz <bar...@extranet.one.pl>

--

You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.





--
Regards,

Marc
Reply all
Reply to author
Forward
0 new messages