CSharp
Last updated
Last updated
Csharp is the favorite programming language of Microsoft. There are many areas to use C# such as Web Application Development, Console Applications and Mobile Application Development via Xamarin. C# programming is very enjoying. But did you know about generating some parts of code using a C# Code Generator? Zontroy is a C# Code Generator, and it speeds up the coding process by generating code in a very short time. Let’s look at a basic example. We are going to use the data model provided below, but you can use your own data model if you like.
You can download SQL sample database
Creating a Zontroy Project
Run Zontroy and create an Empty Zontroy Project.
Enter the information in the form regarding the database and the project. Our data source is local MSSQL and database is a HR database (model is provided above) for this sample. We want to create a CSharp Code Generator project, so select C# as the programming language.
After clicking Create button, the project will be created and ready to work with. At the left side, there is the Entity Window that shows our entities (tables) based on the database. At the right side, there is the Project Window with the project file inside of it.
Next, we are adding a simple template file to generate code. There are three Zontroy template types:
1 – Zontroy Repeating File (zref)
It creates a code file with code implementation for each entity (table or entity class).
2- Zontroy Single File (zsif)
It creates only one code file with code implementation for all entities.
3 – Zontroy Inner Repeating File (ziref)
It creates a folder and a code file with code implementation for each entity (table or entity class).
For our example, we are going to add a zref template to generate a class for each entity in our data model. Right click csharp directory, and click Add File.
Select Zontroy Repeating File (zref) and enter the File Name as below.
Generate Code
With Zontroy, you can write code even in file and folder name areas. This means that Zontroy will take each entity name and tie Controller text with it. File name is going to be like countriesController.cs. For a full list of built-in functions go to docs.
Double click the newly added zref file and paste the code below:
[[[zg-entity…zg-name]]] will be replaced with the name of entity by Zontroy. Code generation is not only about replacing the text, this is just a simple part of source code generation. By using Zontroy, you can do more such as setting the data type of a variable, determining the type of an input (button, text, checkbox, date or any other type) or applying other decision-making mechanisms automatically.
Click Generate button.
That’s all. You can see the generated files in the Project Window.
We have automatically created 7 code file and code lines within them. You can generate much more than this with Zontroy. Hundreds of files and millions of lines…
As the output, the generated countries code file given below:
Zontroy is a very flexible and effective tool. You can generate all tiers in a multi-tier application, even frontend.
Good to know: You can generate C# code using Zontroy.