xml serialization - C# XmlSerializer Order decorator issue with inherited class -


This code is not giving the proposed result, because the order of the elements is not specified:

 < Using the code> system; Using System.IO; Using System.Xml.Serialization; Namespace XmlSerializeTest {class program {static zero main (string [] args) {all class test = new sub-class (); Test.A = "A"; Test.B = "B"; Test.C = "C"; XmlSerializer SerializerObj = New XmlSerializer (Typef (all class)); TextWriter WriteFileStream = New Streamer (@ "C: \ test.xml"); Serializer obz. Serialize (listfilestream, test); WriteFileStream.Close (); }} [Serialable ()] Public Class Base Class {{XML (Order = 2)} Public String B {get; Set; }} [Serialable ()] Public Class Sub Class: Base Class {{Eclipse Element (Order = 1)} Public String A {get; Set; } [XmlElement (Order = 3)] Public String C {get; Set; }}}  

This returns the result:

   

What can be done to get the correct order (A, B, C)?

I have also tried to do these options properly:

  New XmlSerializer (typef (base class), new [] {typef (all class)}) ; New XmlSerializer (typef (all class), new [] {typef (base class)});  

Default .net serial data members in the following order:

  • Data members without order feature without character
  • Data member with order attribute (

Please refer to for more information.

If you want different behavior, you have to inherit your data from the serializer. Note:

Edit / Note:
XML Serializer and DataContrastSilizer use the same command until you need full control of your XML format. , Then I used to go with the data controller instead. Please see this.


Comments