Controlling serialization of property names, etc.

Topics: Web Api
Oct 12, 2011 at 4:36 PM

A quick one, to help me get my head around this new thing...

Would I have to wire in the DataContractSerializer (I've seen Glenn's blog post on this) to control how CLR property, class and collection names get serialized as XML elements?  Or is there a better, more intrinsic way?  In all the examples I've seen to date, you go from C# property name "Name" to XML element <Name>.  Previously, in WCF, I used a [DataMember] to get XML element <name> (or anything that I wanted).

 

Coordinator
Oct 12, 2011 at 7:47 PM

By default we use the XmlSerializer which gives you rich control over how your type is projected into XML.

To control element names you are typically using the XmlElementAttribute.

See http://msdn.microsoft.com/en-us/library/83y7df3e(v=VS.100).aspx for all of the details.

Daniel Roth

From: andrewwebb [email removed]
Sent: Wednesday, October 12, 2011 9:37 AM
To: Daniel Roth
Subject: Controlling serialization of property names, etc. [wcf:275622]

From: andrewwebb

A quick one, to help me get my head around this new thing...

Would I have to wire in the DataContractSerializer (I've seen Glenn's blog post on this) to control how CLR property, class and collection names get serialized as XML elements? Or is there a better, more intrinsic way? In all the examples I've seen to date, you go from C# property name "Name" to XML element <Name>. Previously, in WCF, I used a [DataMember] to get XML element <name> (or anything that I wanted).