Since you also asked about alternatives ...
There was no need to decorate attributes, it was one of the reasons for creating Migrant , a fast serialization library with a simple API. There are some ideas in the library that are also present in protobuf (so we are more or less united in terms of speed and size), but at the same time trying to solve different problems. Among the features other than protobuf, there is a difference between empty and null sets, and the whole serialization is a link based on links and a value based on values ββ(well, you can also consider a link as a special kind of value). README on github should be able to answer most of your questions; if more information is required, just ask.
A simple script to serialize custom objects:
var stream = new MyCustomStream(); var myComplexObject = new MyComplexType(complexParameters); var serializer = new Serializer(); serializer.Serialize(myComplexObject, stream); stream.Seek(0, SeekOrigin.Begin); var myDeserializedObject = serializer.Deserialize<MyComplexType>(stream);
Note that the expected type in Deserialize is only used to have a good compile time type for a deserialized object, you can also use a generic object .
Disclaimer: I am one of the developers.
source share