In C# 4.0, I have a standard object, called “Customer” It has properties and a public empty constructor.
I need to serialize a generic List<Customer> to XML so I can save it, then load it up and deserialize it back.
Is there now framework support for this that is simpler than it was in .NET 2.0 ?
Here’s what I use in my library of goodies:
Not super simple, but it works. Note this deserializes from a path only, but you could easily change it to deserialize from a string, just strip out the
FileStream.The
XmlStringWriterlooks like:I’m simply forcing UTF8 encoding on the XML output.