开发者

How to add a class to protobuf-net

开发者 https://www.devze.com 2023-03-01 06:44 出处:网络
i\'m using protobuf-net and i like it so far but one thing is bugging me. I have a class that i would like to use in a message but its not in my source.

i'm using protobuf-net and i like it so far but one thing is bugging me. I have a class that i would like to use in a message but its not in my source.

like so:

[ProtoContract]
class Test{ 
    [ProtoMember(1)]
    public Otherclass Attr {get;set}
}
but ProtoBuf does not know how to serialize Otherclass and i cant access the code of it. So i need to tell it how to do it but h开发者_Go百科ow?


In v1 you can't, unless it happens to have xmlaerializer or datacontractserializer attributes. Well, that isn't quite true... There is a GlobalOptions toggle that should work in theory, but is not very tolerant if the type changes, as it is inferring a lot.

The better option here is to look at "v2", which is available as an alpha download. Your attributed types should be fine, but you can also tell the type-model how to handle unattributed types; this is all via RuntimeTypeModel.

0

精彩评论

暂无评论...
验证码 换一张
取 消