Powerful Code generation tool Mygeneration

Source: Internet
Author: User
Powerful Code generation tool Mygeneration

Mygeneration is a powerful code generation tool. Generate the various code you need by writing a template containing various types of scripts (C#,vb.net,jscript,vbscript) through the table contents of the database. You can use it to generate ORM entity classes, stored procedures, SQL statements, and so on. I even use it to generate asp.net pages (hehe, I'm lazy).

Mygeneration provides a powerful online template library where you can find the template you need by visiting its website or using the Online Template feature button in template browser. Of course, you can also write your own template according to your needs.

My NHibernate template has been published and a special essay has been written to introduce it. See "Using my mygeneration template to generate NHibernate mapping files and relationships (One-to-one,one-to-many,many-to-many)".

You can download the latest version of it from here.

Introduction to important components

It consists of several important external components, which are commonly used in the following two

Mymeta contains information from the database. We can get the database-related information we want from this library. For example: The database name, the database inside the table, the table inside the primary key and so on.

Zeus provides a framework for mygeneration, the most commonly used is a set of components to the Winfrom package, through this set of components we can dynamically generate the interface we need (we can in this interface to the template users choose to use the parameters), Then the information inside the interface can be used for the build template service.

Working principle Analysis

Mygeneration's support is based on a variety of scripting patterns that work in a consistent way, only expressed in different languages.

My most common is the C # Template. Template is run in two steps, starting with scripting engines executing scripts in template code and interface code, generating C # code for template source and interface source, and then executing template Source to generate the required code. The following figure

Introduction to Template Code templates

C # Template code syntax is very similar to ASP's syntax (note that source is not code, which is generated according to your code).

<%=%> indicates that a field or property is bound.

<%%> represents a script segment where we can write any statement that conforms to C # syntax.

The rest of the content is not parsed. Write directly to the final result in output.

The General C # script inherits from Dotnetscripttemplate, dotnetscripttemplate inside template source can see that he inherits from _dotnetscripttemplate. Interface is similar. Public abstract class Dotnetscripttemplate: _dotnetscripttemplate
{
protected Zeus.UserInterface.GuiController UI;
protected Mymeta.dbroot Mymeta;
protected Dnp.Utils.Utils dnputils;
Public dotnetscripttemplate (Izeuscontext context): Base (context)
{
This.ui = context. Objects["UI"] as Zeus.UserInterface.GuiController;
This. Mymeta = context. objects["Mymeta"] as Mymeta.dbroot;
This. Dnputils = context. objects["Dnputils"] as Dnp.Utils.Utils;
}
}

Dotnetscripttemplate inside the template needs to use the database information and interface information is also quoted, we can through the Mymeta to get the information inside the database, and from the UI to obtain and template related parameter settings information.

The code is written in the template render method. The page code is written in the Setup method.

Using configuration Files

Mygeneration supports the use of configuration files, the default Settings in edit ... We can see.

Language mapping defines the database and language (C#,VB. NET, etc.).

The database Target mapping defines the field correspondence between the databases and the ado.net.

User Meta-date allows users to set their own custom configuration files.

In the template we can access the contents of the input["__dbdriver" syntax.

The following are common:

__defaultoutputpath
__dbdriver
__dbtarget
__language
__dbtargetmappingfilename
__dblanguagemappingfilename
__usermetadatafilename

You can look at the inside of the template catalog inside the tutorials/c# inside the CHARPT1 example (Charpt2 is also a good example, but write a bit cumbersome).

Shortcut Button Detailed

Template Browser can see all the templates.

The first button function is refreshing.

The second button is to toggle the display mode. Browse by directory and browse by namespace.

The third button is to view the online template library.

The fourth button is to open the stencil.

The fifth button and the sixth button work together, the point sixth run time, the parameter will record in the Znip file which you specify (in fact is in the XML format), the next time runs the point fifth button, then chooses to your saved Znip file, will automatically load your configuration.

The seventh button is the Run stencil.

The first button action is to open a file.

The second button action is to display the Template browser window.

The third button is to display the Mymeta browser window and view the database information.

The fourth button works by creating a new item. You can use more than one template to complete your task (I generally do not).

The fifth button action is to open the default output path.

The sixth button is to create a new JScript Template

The seventh button is to create a new VBScript Template

The eighth button is to create a new C # Template

The Nineth button is a new vb.net Template

The tenth button is to view the Mymeta property (do not know how to use, will be used also please advise me)

The 11th button function is to view language Mapping.

The 12th button function is to view Dbtarget Mapping.

The 13th button is to view user Meta Data.

The 14th button is to view global User Meta Data.

The first button function is to save

The second button function is to save

The third button is to view template information

The fourth button is to display the console

The fifth button function is to run the template

Try to write the first template

Select File-->new-->c# Template in the main menu. Mygeneration will generate the following template code for you. This is the contents of template code. <%
public class Generatedtemplate:dotnetscripttemplate
{
Public generatedtemplate (Zeuscontext context): Base (context) {}

//---------------------------------------------------
Render () is where your want to write your logic
//---------------------------------------------------
public override void Render ()
{
%>
Can toggle in out the script like this
<%
Output.writeln ("Hello world.");
}

}
%>

We run this template to see the output. The contents of the%><% are output directly to the result, and the content of the Output.writeln is output to the result. Output is the property of the interface inside. There are a lot of features. See the Zeus help file.

Can toggle in out the script like this
Hello World.

We found the interface code, and found that there were a few comments in it. We remove the annotation after the code is as follows public class Generatedgui:dotnetscriptgui
{
Public Generatedgui (Zeuscontext context): Base (context) {}

//-----------------------------------------
The User Interface Entry Point
//-----------------------------------------
public override void Setup ()
{
* * Uncomment CODE BELOW to the UI * *
Ui. Width = 100;
Ui. Height = 100;
Guilabel Lbldemo = UI. AddLabel ("Lbldemo", "Demo", "Demo Tooltip");
Ui. Showgui

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.