Generate Order property on your DataMember attributes

Sep 27, 2010 at 3:10 PM

DataContractSerializer needs order property to be set to work correctly. See http://stackoverflow.com/questions/2526330/data-contract-serialization-not-working-for-all-elements .

I found method Xsd2Code.Library.Extensions.Net30Extension.CreateDataMemberAttribute(CodeMemberProperty prop). Is this the right place for adding property ?

Example :

[System.Xml.Serialization.XmlElementAttribute(Order=0, ElementName="xxx")]

http://wscfblue.codeplex.com/ has support for generating this property but only generates code to work with the XmlSerializer.

Any help ?

Sep 27, 2010 at 5:58 PM

Hi,

Thank you for your post.

Go into Process method in Generator.cs.

On the new instance of XmlSchemaImporter, add generation option like this :

GenerationOptions generationOptions = GenerationOptions.GenerateOrder; 
var exporter = new XmlCodeExporter(ns); var importer = new XmlSchemaImporter(schemas, generationOptions, new ImportContext(new CodeIdentifiers(), false));

This change will be integrated in next version of xsd2code (Version 3.4).

Pascal.

Sep 28, 2010 at 7:41 AM

Wow that was fast ! :)

Thanks !

Sep 28, 2010 at 9:38 AM

Sorry, i need to generate [System.Runtime.Serialization.DataMemberAttribute(Order=4)] and not System.Xml.Serialization.XmlElementAttribute(Order=0, ElementName="xxx")].