There are many tools out there that can be used for the generation of JSon and or XML related coding in many languages wether it be generating classes from a schema or a document or the other way around generating schemas based on classes or objects
In this short article we will go over some of the reasons why you should be using Xsd2Code, it's main features and properties that put it above it's competitors.
Xsd2code not only has quality, easily readable code it also has many other features, it does not simply create your class in C# it also handles things like lazy generation.
Lazy initialization/generation/Loading of an object means that its creation is deferred until it is first used. Lazy initialization is primarily used to improve performance, avoid wasteful computation, and reduce program memory requirements. These are the most common scenarios:
- When you have an object that is expensive to create, and the program might not use it. If the user never asks to display or use the data in a computation, then there is no reason to use system memory or computing cycles to create it. By lazily initializing, you can avoid wasting system resources when the object is not used.
- When you have an object that is expensive to create, and you want to defer its creation until after other expensive operations have been completed.
You can enable lazy loading in the Output property settings like shown :
Here's what it will look like before you turn Lazy Loading On :
And this is what it will look like after :
Lazy pattern is used when it's possible, and now It initializes complex types when the property is accessed
With Xsd2Code you can handle almost anything. If you're just looking to turn your schema into a class you can, but if you take a look at the veritable treasure trove of options you might not only be blown away but also learn new things, and although it may seem scary at first most of the settings are simple switches to have things on or off. Xsd2Code is able to gracefully combine simplicity of use and depth.
For example with just a click you have serialization and deserialization methods generated for you in your resulting class and these functions will adapt to the schema being used by XSD2Code.
Here's how to enable this setting and what it will look like :
And these are the various functions that will be generated for you :
You can see these functions and the processes of serialization and deserialization here.
Xsd2Code is not only easy to install, as you can simlpy integrate it NuGet package into your VisualStudio (wether it be the Pro, Ent, community 2019, 2017 or older versions), once impleted with only a few clicks you can have your various classes generated in C# with many options. To add to this productivity gain, the serialization code is automatically generated so you don't have to worry about it, but on top of generating this code for you, XSD2Code can do it in multiple formats, have a look :
First as seen before you have to enable serialization in the settings, precisely in the Output advanced code settings section as shown here :
You may notice the different options, depending on what you need you could switch from BSon, JSon to XML or even to MessagePack. For now you have to choose, but you will soon be able to have XSD2Code handle all of the formats.
Here's what the Deserialize function will look like depending on the chosen format :
- JSon :
- BSon :
- MessagePack :
- XML :
Xsd2Code also has tight VS integration, including context menu integration and a custom build tool (which means that if you reference the XSDs in your project and specify the custom tool, it will automatically update the code as you update the XSD).
You can see in our installation or quickstart pages this advantages in effect
To add to the expansive list of options, now, thanks to our recent update, you are able to generate the code needed to serialize in all available formats, so JSon, BSon, MessagePack and XML, all you need to do is look at our new setting to activate additional serializers.
You'll find this in the Output advanced code settings section, as shown here :
You can select the different serializers you want to have in your generated classes, and the various serializers will look like this.
Here's a free tip, consider using messagepack if size and storage is important to you, this compact binary JSon format can help you.
CodeNGine Technologies, 19 Avenue, de la gare, 34770 Gigean, France. 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