protobuf net - Overriding serialization method of inbuilt types -
i need switch different methods of serialization inbuilt types (datetime example) during runtime or @ least during model initialization. best approach this? have tried surrogating them custom model (runtimetypemodel.add(typeof(datetime), false).setsurrogate(typeof(uint)) ), got error "data of type has inbuilt behaviour, , cannot added model".
it isn't scenario have considered hugely, honest. of "inbuilt behaviour" types really bad idea change implementation, since part of protobuf specifical; however, in case of datetime, timespan, decimal , guid there perhaps alternative layouts supported. can ask want here? there may better ways it. equally important be: magnitude? if few cases, shim property might preferable, example:
public datetime when {get;set;} [protomember(4)] private uint whenserialized { { return yourconverter.fromdatetime(when); } set { when = yourconverter.todatetime(value); } } it may possible enable "surrogate" handling these types, can't use surrogate directly uint (you can use surrogate struct or class has uint, though).
Comments
Post a Comment