views:

41

answers:

1

Hi all,

just a quick question. I have been looking around searching for information about the order of elements in the serialization xml document for an object.

As far as I know the order (unless specified using XmlElement attributes) will be the order the properties are present in the type's code. This order, however, is not guaranteed.

And that is what I am looking for. The reason why this order is not guaranteed. I want to have a look at specs or whatever definitive information that can shed some light on this for me and Google fails to deliver so I was hoping you guys can help me out :)

Thanx in advance, Anton.

+1  A: 
  1. In writing a spec, one should not guarantee anything that isn't relevant to the task at hand, as all that will do is restrict implementation for no gain. You could be forced into suboptimal or even buggy behaviour and not have any benefit from it.
  2. If developers started depending upon order in some way, then they would find their code broken if the author of the class changed the order of the properties and/or fields. This would then create a restriction on said author on something that they generally are free to alter as they see fit.
  3. There is no such order. Partial classes can define properties and fields in separate files, and move from one to another as development progresses. The fields used in the implementation of automatic properties "live" somewhere other than the class definitions. The order itself is therefore not guaranteed, and hence cannot have another guarantee built upon it.
  4. If a custom requirement beyond that of XML serialisation itself required an order, the class author can customise the specialisation. They're likely to need to anyway as custom requirements tend to go hand-in-hand with other custom requirements, or else need greater degrees of future proofing than the default implementation provides.
Jon Hanna
Very insightful, thanx.
Anton