Implementing our own serializers in C # - tips and fixes

We probably need to write our own serializers for the classes in our (large) C # application. The BinarySerializer is too slow and verbose, and protobuf-net has problems with the interface properties (of which we have loads).

Does anyone have any good tips and / or warnings? I suspect we should use BinaryWriter and BinaryReader , but we haven't done a lot of bit-messing around in C #, and any gotchas will be appreciated!

Similarly, does anyone know of a manual serializer with source code that I could look at?

+4
source share
2 answers

Tips / Warnings? This can be serious code. I suggest that it is easier to write simple code that transforms your existing model into a simple DTO that can be serialized trivially according to your choice of an existing serialization API. The presence of the DTO level (separate from the domain objects) also allows to simplify the maintenance significantly - you can reorganize your domain objects without violating the serialized data.

The parameters for this are yourselves (remember that you emphasized that the model is quite complex and you are not a bit violinist):

  • Manually record serialization of record type very easy to make mistakes, very laborious.
  • write a general library; crazy amounts of work solving all edge cases

And after that, you realized the serialization format, which works reliably, extensibly and supports the scripts you need (inheritance, etc.).

+3
source

Consider Type Convertors . We use them extensively with ViewState, and they work great.

0
source

All Articles