Monday, March 9, 2009

.net serializer/deserializer

Load Scene/Save Scene Complete;

Add native application running test functionality;
Layout Save/Load
Here is the structure of scene load/save part.

Why not use TiniXML to do all these jobs?
.net XML Serializer is quite easy to use and i have ready made property classes for property grid, i only have to serialize these property classes into an xml file instead of serialize the whole binary object. It also supports Generic Template List serialization.The lack of supports for Dictionary is a pity though( i have to transport elements of dictionary to a list for this.).

However in deserialization procedure
, TiniXML is much easier to use than .net xml deserializer.

First, i need to prepare an empty constructor for every class i want to deserialize. For this i have to change every referenced member of class to pointer member so i can easily initialize them to NULL in c++/cli for the empty constructor.
Next, in the deserilization procedure it will call every property's set function automatically, so
i have to create certain object after some important property are read at the beginning. Thus i need to fix orders for properties. Add this [XmlElement(Order = ..)] for this step.[XmlIgnore] to ignore the property you don't want to serialize or native member.
The only issue i haven't solved is the situation where you have two classes with inheritance relation. The parent classes' properties are prior to the children classes' properties in the serilized xml file. And there are always situation where the parent class includes an pure virtual object which can't be instantiated first and need to pass children's pointer instead.So deserialize children classes' properties first to instanciate a children class first is the only way to solve this inheritance relation's deserialization.But there is no way to change this parent-children properties order via xml serilizer.( i searched internet and didn't find any one solve this.) I have to change inheritance relation to include relation.

Finally i found i used much more time to solve all these issues but save quite a lot of code lines(I believe) than using TiniXML. Hope serialization of .net can become better in the future.


Post a Comment