Customize XML Serialization using IXmlSerializable

XML Serialization in .NET provides an incredibly useful (and easy) way to turn objects into XML and back again. However, in some situations, you may need more control over how your object is serialized. Recently, I found myself needing to serialize an object that contained a number of property name/values – stored using a NameValueCollection. However, you can’t serialize this using the XmlSerializer class in .NET. I could have switched to using an array  – at least for the serialization part – but this would have serialized the whole lot as a series of elements – and I wanted to do this using attributes.

[Apologies – I’ve had to snip the code from here, as the layout kept messing around]

Read more here: Customize XML Serialization using IXmlSerializable.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.