Tutorial on Codesmith (1): Overview We can learn the basic steps of automatically generating code using Codesmith by using Codesmith to automatically generate nhiberate code from a database:
Choose to use the appropriate template, codesmith with the development package with a large number of commonly used templates, if not found the appropriate template, Codesmith support custom templates.
Select the appropriate parameter settings for the template.
Generate code automatically (can be any type of code, C#,java,. XML text, etc.)
Its core is the code template file, with Codesmith with a lot of commonly used templates, you can query through the template browser, in addition to the internet there are many third-party development of templates, before use can check whether there are ready-made templates, or you can modify the existing template to complete the need for automatic generation of code.
When developing applications, many people like to copy the code from the previous project and modify it to meet the new project, which often has many commonalities (think of C + + template classes, C # generic, etc.), Codesmith is used to create templates for these similar code, You can then automatically create the required code by setting the properties (the different points of the code).
This example provides a simple example of how to create a custom code template. Codesmith provides support for the integrated development environment of Visual Studio, in this case, by creating a template to automatically generate the AssemblyInfo.cs needed to simplify each C # project, when developing C # applications, It is generally done by manually modifying the AssemblyInfo.cs properties (or Copy & Paste:-)).
First we use Visual Studio to create a C # HelloWorld underneath (either the console or the WinForm Project) to open the AssemblyInfo.cs in the project
Using System.Reflection;
Using System.Runtime.CompilerServices;
Using System.Runtime.InteropServices; General information about a assembly is controlled through the following//set of attributes.
Change this attribute values to modify the information//associated with a assembly.
[Assembly:assemblytitle ("HelloWorld")]
[Assembly:assemblydescription ("")]
[Assembly:assemblyconfiguration ("")]
[Assembly:assemblycompany ("Microsoft")]
[Assembly:assemblyproduct ("HelloWorld")] [Assembly:assemblycopyright ("Copyright? Microsoft 2013 ")] [Assembly:assemblytrademark (" ")] [Assembly:assemblyculture (" ")]//Setting ComVisible To false makes the "types in" assembly not visible/to COM components.
If you are need to access a type in this assembly from//COM, set the ComVisible attribute to true on that type.
[Assembly:comvisible (FALSE)]//The following GUID is for the ID of the typelib if this project is exposed to COM[Assembly:guid ("72797715-64b9-4bab-a49f-f55e8a0a18d7")]//Version information for a assembly consists of the foll Owing four values:///Major Version//Minor version/build number/Re Vision////can specify all of the values or you can default the builds and Revision Numbers//by using T He ' * ' as shown below://[Assembly:assemblyversion ("1.0.*")] [Assembly:assemblyversion ("1.0.0.0")] [Asse Mbly:assemblyfileversion ("1.0.0.0")]
To use Codesmith, we add the Codesmith project file to the HelloWorld and create a template file Assemblyinfo.cst