Tuesday, April 19, 2011

Serialise value to XML in one line of C#

This one-liner is useful in the immediate window of Visual Studio to serialise an object to XML:

new XmlSerializer(OBJECT.GetType()).Serialize(new System.IO.StreamWriter(@"c:\temp\x.xml"), OBJECT);

Note that this is not production ready because it does not dispose of objects that should be disposed!

0 comments:

Post a Comment