Exporting XML

I added the logic to save all my chunk data to one file, and it’s working quite well. I still need to add the logic to read that information, but this is a good start.

I hit a couple of snags on the way that are worth mentioning. C#’s XmlSerializer class cannot serialize multidimensional arrays (e.g. int[, ] array), which means that if you don’t want to reimplement the serialized to handle them, you have to have a property that coverts a multidimensional array to a multi-indexed array (e.g. int[][] array). This property must be public, since XmlSerializer can’t handle private elements, and it must implement both a getter and a setter. Additionally, the class to be serialized must have a no-arg constructor.

All-in-all, I think the things I’m doing to leverage XmlSerializer are hackish, but worth the built-in power of the class. Since this is a dev tool, I’m not too concerned about it being perfect. In the future though, I think that designing classes that need to be serialized around these kinds of constraints would be cleaner and more efficient. 

 

piebie

 

Leave a Reply

Your email address will not be published. Required fields are marked *