Write the code generator by yourself (1). Write the Code Generator

Source: Internet
Author: User

Write the code generator by yourself (1). Write the Code Generator

I thought of a code generator of my own for a long time. It was simple and enough for my own use, so I had no time. I was idle recently, so I made up my mind to write a small software to complete these tasks for me. I wanted to use WPF for development. However, WPF only learned basic things, and I am not good at interface design. I guess I used the WEB method to do this, the interface also draws on the design of the company's projects.

The specific functions and precautions are as follows:

I. Function Description:

1. the C # entity class can be generated based on the data table structure.

2. generate code (NVelocity. dll) based on Template)

For those who want complex functions, I can only say sorry to you. I don't have it here, because this software is used by myself and is enough for me. I will upgrade it if necessary in the future. Let's take a look at the generator first.

Ii. components used

1. artDialog: Dialog Box plug-in

2. pqGrid: Table plug-in

3. highlight: Code highlighting plug-in

4. TreeView: Tree plug-in

5. NVelocity. dll: Template generation component

 

Iii. interface:

 

 

Iv. project structure:

 

5. configuration item settings

 

Vi. basic use of NVelocity

// Define a template Context
VelocityContext vltContext = new VelocityContext ();
Dictionary <string, string> dic = new Dictionary <string, string> ();
Dic ["dudu"] = "blog Garden ";
Dic ["Jimmy"] = "softcomz ";
// Input the parameters required by the Template
VltContext. Put ("dic", dic); // sets the parameter as an object, which can be referenced by $ dic. dudu in the template.


<Html>
<Body>
$ Dic. dudu
$ Dic. Jimmy
</Body>
</Html>

 

 










How to compile the Aspnet Code Generator

Asp.net itself does not have a code generator, which is developed by a third party. if you want to, you can also create your own code generator. In fact, it is a template that allows the generated code to have the same naming rules, file preparation, access mechanisms, and so on.

When code generation is used, the prototype of the transaction class, data class, and database outline is usually used according to the specific framework. We will generate these entity classes quickly and access the DAO class for data, these classes encapsulate some basic methods.

Specifically, the usage skills are based on different generators, because after all these third parties do not have a unified specification, they are all habits.

I have compiled a program myself, but how can I implement it with a compiler?

Write the compiler by yourself. You can go to the library to borrow a book called Dragon, whale, and tiger.
Then, C \ C ++ is used to compile lexical analyzer, syntax analyzer, semantic analyzer, and intermediate code generator.
After learning the assembly language, use C \ C ++ and Assembly to compile the target code generator and code optimizer.
In this way, you can successfully compile a compiler. At your current level, at least half a year or a year ......
In fact, this stuff can be designed as a graduation project, and it may be better.

Are you sure your teacher asked you to write a compiler? Write a makefile...

Related Article

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.