The latest codesmith3.2 (. net2.0) Tutorial 2: The first time codesmith was used to generate code

Source: Internet
Author: User
Let's review the content of the previous section: We use codesmith explorer to understand the basic structure of the template file.
The following code uses the codesmith template to generateCode:

1. generate code

When you follow the steps in the previous section, now you have prepared everything for generating our first template code. Next, you can press the generate button under the template property page. codesmith will extract the attributes you entered and integrate them into the generated code. Next, you can use Ctrl + C to easily copy the generated code.

The code window contains 320 rows of hash table class code, which is embedded with the idictionary, icollection, ienumerable, and icloneable interfaces. If you are an experienced developer, you certainly know that if these templates are all well-established and never-changing, it is definitely the most annoying thing. Codesmith is the most ideal tool because you can generate your own template, which ensures sufficient flexibility to use the template in the future. Everything is so consistent with oneProgramMember's mind.

2. Understand the template Structure

let's take a look at the cshashtable. CST template code ., The template contains the structure that codesmith uses to generate code. Return to codesmith explorer and right-click the template and choose edit. Codesmith studio will be started to open the template for editing.

in the following sections, you will learn more about the details. Now, you only have a general understanding of codesmith. Secondly, have you found that codesmith's template language is very similar to ASP. NET? Start with some delimiters and include some attribute declarations. These attributes will be used in subsequent code. For example, the template contains the following line:

namespace <% = classnamespace %>

the class namespace is followed by the attribute name.

if you do not like the cshashtable template, you can modify it according to your ideas. For example, you can add some comments to the interface. Remember to make changes and click Save.
3. Review

perform the following steps to generate a template using codesmith:
(1) start codesmith explorer
(2) Select template
(3) enter the attribute value
(4) generate code

OK, the first template code is generated!

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.