Paste XML as C# Classes in VS 2012

In the Visual Studio 2012 IDE, a new feature is introduce to convert XML document into C# classes as a Serializable type.

In the .NET framework 4.5 there is another Paste Special option is exists in the Edit menu which enables you to copy the XML as C# Classes.

Paste-xml-as-classes.png


Copy the XML  you want to create a class/classes for, place the cursor in a class file on the location you want the code to be added and select the following menu items:

  • Edit.
  • Paste Special.
  • Paste XML as Classes.

And you're done.

Suppose you have following XML File. 
xml-in-vs-2012.jpg

And when you paste the above XML using Paste XML as classes. It will looks like that.

xml-as-classes.jpg