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!

1 comment:

  1. Man I love this site. It is just so awesome. Whatever you want, all are available here.