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
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
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 :
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.
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.
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.
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 :
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
CodeNGine Technologies SIRET: 85257252800010, VAT : FR 62852572528
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