Visual Studio tip: paste json/xml file as class

I’m a long time listener of .NET rocks and today during my drive to work while listening to TDD on .NET and Java with Paul Mooney, Carl mentioned a cool tip I want to share with you.
In the past I have use XSD.exe to create classes from XML files for serialization purposes (and similar tools for json) but no more.
Using Edit –> paste special (which I didn’t even knew existed until today) you can create C# (or VB.NET) classes from
You can copy an XML file to the clipboard and and so the following file:

<?xml version="1.0" encoding="UTF-8" ?>
        <Overview>A man struggling with his faith is haunted by the sins of his past but is suddenly thrust into the role of defending humanity from the gathering forces of darkness.</Overview>

Will become this class(es):
And it would also work for json files as well.
It’s not perfect, I found that I needed to “re-copy” the source after each use and the “paste as xml classes” option will only appear for .NET 4.5 (and above).
No more using external tools to get serialization up and running – a big time saver.

Happy coding…

One thought on “Visual Studio tip: paste json/xml file as class

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.