To Serialize a class with protobuf-net, you neet to provide the class and property attributes [ProtoContract] and [ProtoMember(n)] — where n is 1,2,3,..,etc
Appart from cloning to a mirror image of a class, is it possible to serialize/deserialize a class we don’t have control over?
For example:
using ProtoBuf;
- Serializer.Serialize<Exception>(OutputStream, exception);
or
- Serializer.Serialize<Tuple<Data,Exception>>(OutputStream, dataWithPossibleException);
NB. say Data has [ProtoContract] / [ProtoMember] and the others do not.
possible approaches:
- It would be nice if we had “extension attributes” that worked like extension methods. [not possible]
- replicate the class locally and then copy to / from the object before serializing / deserializing [that would work, but productivity goes down]
- generate an external proto file/definition for the class and store this in resources? [anyone know how to go about this?]
There are options in v2 here:
Now, I think some of that addresses some of your points. If you can fully specify a scenario that is problematic I might be able to be more specific (or think of new ways of torturing the code to make it work).
But to answer the headline question (non-decorated): yes, in v2