Home  /  Blog  /  Quickstart 

A quickstart to Xsd2Code

Ferbuary 2021

Once you've successfully installed xsd2Code all you have to do is put your schema or data file into the project in Visual Studio from there you need to right click the file and in the context menu you should see a new option, xsd2code++, hovering over it will reveal, depending on the type of file, new options, you could convert your file from and into various formats, or you could start generating your classes with the run xsd2code++ option

Tooltip that appears when you rightclick on the Json schema while Xsd2Code is installed

Once the tool starts running you will see a preview of what your generated class will look like, if anything bothers you in it, do not fret xsd2code++ offers quite a large number of settings on the left-hand side of your screen

The options page with settings on the Left-side and a preview of the generated code on the right-sight

For example, if you prefer your properties Auto-implemented meaning more concise way this can be changed like many other things. This setting can be found in the Properties section nested in the Output property settings , what we're looking for is the Automatic properties setting that is by default on False. Like so :

Shows the path to take to get to the AutomaticProperties

Once you put this setting on True you should see the program regenerate your class with the appropriate changes, in our example it look like this.

The properties with the Automatic getters and setters

Instead of

The properties with the manual style of getters and setters

You can check out our other articles to see what can be done with the other settings, but for now let's move on. Once you're satisfied with your options, you can continue by clicking generate at the bottom right corner  Once your class is generated, you're ready to go, have fun ! But if you're willing to stay a bit longer we can show you how to make use of some of the functions this tool can generate for you to write and read json files. 

Serialization

By default the generation of these functions is turned off, to turn them on you need to look for the Serialization option in the Output advanced code settings.

The properties section that lead to turning the options to enable serialization

Make sure to have the proper filetype selected in the DefaultSerializer in our case it's Json, make sure it is all Enabled in the Enabled setting by setting it to true. (If you see errors relating to NewtonSoft don't worry we'll get to it)

Once the settings are set and you press "generate" your class or classes should have a couple of new functions : 

-SaveToFile         xsd2code serialization SaveToFile


-LoadFromFile    Shows the LoadFromFile function


-Serialize           xsd2code serialization


-Deserialize       xsd2code deserialize

You won't need to interact with the serialization part of the code unless you know what you're doing

Assuming you're working with single objects and not a list of them when you use the Customers' (in our case) SaveToFile property with a valid path argument it will write that instance of the object into the file after serializing into the right format. The same thing but in the opposite direction happens when you LoadFromFile

But you might've seen errors in the class, that comes from the fact that you probably haven't installed Newtonsoft, it's because these functions use the Newtonsoft Json.Net. You need to add the NuGet of Newtonsoft.Json, once you did that everything should work fine. For the other formats other NuGets are used be sure to keep an eye out for those, if something is missing in the fuctions you're most likely missing a NuGet

Thank you for using our product, if you want to learn check out our other articles on the things you can do with XSD2Code++.

>

Terms & privacy

Terms of uses · Privacy policy 

Contact

CodeNGine Technologies, 19 Avenue, de la gare, 34770 Gigean, France. SIRET: 85257252800010, VAT : FR 62852572528
codengine.technologies@xsd2code.com

About the company

CodeNGine Technologies is software company based in the South of France that provides an advanced productivity code generation tool to developers using XML and JSON


Copyright © 2021 CodeNGine Technologies