Tuesday, March 12, 2013

Quickly create (simple) serialization classes from xml

So Visual Studio 2012 and .net 4.5 has a pretty nifty feature for when you quickly need to handle some arbitrary xml document, "paste xml as classes". In order to do this, copy your xml to the clipboard, place the cursor in a code file, utside any class definition, and go to the edit menu -> paste special -> paste xml as classes. Voila! You now have something you can use to serialize and deserialize your xml. Very simple and ugly, but sure beats hacking them yourself.

This feature require a .net 4.5 project in VS2012, but only the actual function, the generated classes can be used in .net 4 and older.

Read more here: http://msdn.microsoft.com/en-us/library/hh371548.aspx