Home » .NET » Visual Studio tip: paste json/xml file as class

About Dror Helper

Dror Helper

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
 
 
 
image_thumb[1]

You can copy an XML file to the clipboard and and so the following file:

<?xml version="1.0" encoding="UTF-8" ?>
<Data>
    <Series>
        <seriesid>273690</seriesid>
        <language>en</language>
        <SeriesName>Constantine</SeriesName>
        <banner>graphical/273690-g2.jpg</banner>
        <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>
        <FirstAired>2014-10-24</FirstAired>
        <Network>NBC</Network>
        <IMDB_ID>tt3489184</IMDB_ID>
        <zap2it_id>EP01921172</zap2it_id>
        <id>273690</id>
    </Series>
</Data>

Will become this class(es):

image_thumb[3]

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…

Reference: Visual Studio tip: paste json/xml file as class from our NCG partner Dror Helper at the Helper Code blog.
(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a sysadmin Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. Introduction to NGINX
2. Apache HTTP Server Cookbook
3. VirtualBox Essentials
4. Nagios Monitoring Cookbook
5. Linux BASH Programming Cookbook
6. Postgresql Database Tutorial
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments