CodeSmith Introduction

5. CodeSmith practical skills (E): the use of inheritance can change the code generated
When you build your application, you often need to repeat to complete certain tasks, such as writing data access code, or generate custom collection. CodeSmith is particularly useful in these times, because you can write a template automatically complete these tasks, thereby not only improve your work efficiency and to automate those most tedious task. CodeSmith comes with many templates, including all corresponding. NET collection type of template and the template used to generate stored procedures, but the real power of this tool is the ability to create custom templates. To enable you to start, I l quickly explain how to generate custom template.
11. CodeSmith practical skills (11): Add designer support
You can see the left side of the property is what I declared in the template properties. If I enter “SingletonClass” as the class name, and click the Generate button to generate Figure 3 will be displayed at the bottom of the class.
Description = “Car Template”%>
7. CodeSmith practical tips (7): copy attributes from the parent template
8. CodeSmith base (VIII)
CodeSmith written by the Eric J. Smith, and can be downloaded in http://www.ericjsmith.net/codesmith.
The next part of the template attribute declarations, where each template can be declared to run in the specified property. On the template, I only want to use the property is just a string, so the property declared as follows:
As you can see, this template accepts a string input and use the class name to generate a separate class. In the template body, use with ASP.NET in the same start and end tags. In this template, I just insert the property values, but you can also use any type within these tags. NET code. In the template is complete, you can double-click it or open the application from CodeSmith will load it into the CodeSmith. Figure 4 shows the CodeSmith has been loaded into the template.
2. CodeSmith practical skills (b): Use FileNameEditor
1. CodeSmith template based class
13. CodeSmith practical skills (XIII): Use CodeTemplateInfo object
3. CodeSmith practical skills (C): Use FileDialogAttribute
<% @ CodeTemplate Language = "C #"
9. CodeSmith practical skills (9): override the Render method to control the output
4. CodeSmith practical skills (D): using extended attributes
7. CodeSmith base (VII)
4. CodeSmith base (D)
<% @ Property Name = "ClassName" Type = "String" Category = "Context"
2010 年 06 月 22 日
5. CodeSmith base (E)
8. CodeSmith practical skills (8): the generated code to the output file
CodeSmith based series:
CodeSmith Development Series data summary:
2. CodeSmith base (B)
Description = “Class Name”%>
“Terrylee” CodeSmith practical skills series:
TargetLanguage = “C #”
1. CodeSmith practical skills (a): StringCollection
generated using a custom template
3. CodeSmith base (C)
6. CodeSmith base (VI)
12. CodeSmith practical skills (12): automatically execute SQL scripts
6. CodeSmith practical skills (F): Using XML attribute
CodeSmith is a template-based code generation tool that uses syntax similar to ASP.NET to generate any type of code or text. Many other code generation tools with different, CodeSmith does not require you to subscribe to a specific application design or architecture. Use CodeSmith, you can generate a strongly typed collection includes simple and complete application, including anything.
1. CodeSmith base (a)
CodeSmith templates that can be just in any text editor to create the text file. The only requirement is that they use. Cst file extension to save them. I am going to generate a sample template will accept a string, and then generate a class based on that string. The first step is to create a template to add the template header, it can declare a template language, target language and a brief description of the template:
14. CodeSmith practical skills (XIV): Use the Progress object
“kid-li” translated CodeSmith API Series:
10. CodeSmith practical skills (10): program implementation through template
ClassName attribute of the attribute declaration will appear in the Properties window in CodeSmith, so that you can specify it in the template at run time. The next step is to actually build a template of the main, it is very similar to coding in ASP.NET. You can see in Figure 3, the main body of the template.
CodeSmith is easy to use, if properly applied, can produce some incredible results. Applications for code generation part in one of the most common data access layer. CodeSmith includes a special program called SchemaExplorer set can be used to from the table, stored procedure, or almost any other SQL Server? Object to generate a template.
15. CodeSmith practical skills (xv): Use the shortcut keys

No comments allowed