使用 ProtoBuf-Net 进行两组不同的序列化

Using ProtoBuf-Net for two different sets of serialization

我正在使用 ProtoBuf-Net 通过 TCP 发送装饰对象 - 它的效果非常好。

但我想将相同的对象也序列化到一个文件中,但具有不同的装饰。也就是说,我想在这里保存其他属性。

我认为在运行时无法操作属性,那么我还有哪些其他选择?

提前致谢!

(如果之前有人问过这个问题,我很抱歉,但我无法找到搜索词 'different' 的任何内容)

查看文档:

Alternative to attributes In v2, everything that can be done with attributes can also be configured at runtime via >RuntimeTypeModel. The Serializer.* methods are basically just shortcuts to >RuntimeTypeModel.Default., so to manipulate the behavior of Serializer., you must >configure RuntimeTypeModel.Default.

或者这个问题: Protobuf-net serialization without annotation

基本上,您可以通过 RuntimeTypeModel 自己配置所有内容,而不是注释