0

I am using ProtoBuf-Net to send decorated objects over TCP - and it works like a charm.

But I want to serialize the same objects also into a file, with a different decoration. That means, I want to have other properties saved here.

I don't think manipulating attributes is possible at runtime, so what other options do I have?

Thanks in advance!

(I'm very sorry if this was asked before, but I was unable to find anything with the search term 'different')

oo_dev
  • 777
  • 7
  • 20

1 Answers1

2

See the documentation:

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.

or this question: Protobuf-net serialization without annotation

Basically, instead of annotations, you can configure everything yourself through the RuntimeTypeModel

trykyn
  • 451
  • 2
  • 9
  • 1
    And more specifically: a *second* model instance (`TypeModel.Create()`). Good answer. – Marc Gravell Jul 06 '19 at 07:22
  • Thank you and you @MarcGravell for confirming. Could I let the 1st set still use the annotations and just the 2nd programmatically? – oo_dev Jul 24 '19 at 13:49
  • 1
    @copa017 yes; as long as you pass `false` as the auto-configure parameter when adding types to the 2nd model, it ignores everything – Marc Gravell Jul 24 '19 at 15:06