Codesmith is an operation mechanism that imitates Asp.net.CodeGenerator, the pre-compiled instruction and body content of the runtime analysis template (equivalent to the aspx file), generate a Code inherited from codesmith. engine. codetemplate (equivalent to system. web. UI. page) or the source code of a class (equivalent to the codebehind class) specified in the inherites precompilation command, and compile it. then, bind the class to a propertygrid, and ask the user to edit the parameter and execute the _ rendermethod1 (equivalent to render) method of the generated class to generate the final code. this mode isolates the easily generated content from the relatively stable data source for generating code.
Most codesmith users I know generate object classes, stored procedures, or Asp.net interfaces based on the database structure, while codesmith provides schemaexplorer for reading the database structure, the pre-compiled instruction declaration type in the template is schemaexplorer. tableschema attributes can be used. most templates use schemaexplorer to obtain the database structure.
Propertygrid is a bridge between the user and the class generated based on the template. By marking editorattribute on the attribute or attribute type, you can arbitrarily extend the representation of this attribute in propertygrid, see http://www.microsoft.com/china/msdn/archives/library/dndotnet/html/usingpropgrid.asp for details
However, codesmith does not support attribute tags defined in the template. it is inconvenient to write such complex code in codesmithstudio even if there is one. the solution is to write a base class of the template in vs.net. engine. codetemplate inheritance), and then let the template inherit from the base class by specifying the inherites keyword, then you can use editorattribute as desired. I have created a template base class that can be used to generate multiple Nhibernate entity classes, XML ing and aspx interfaces. It can also serialize the filled content to an XML file and deserialize it from an XML file. I didn't use tableschema to generate code data sources. Instead, I had a custom data structure and could be edited manually using xtragrid. Of course, schemaexplorer can also be used to retrieve the structure from the database. the structure of this base class is as follows:
| Classgenerator |
| + Assembly |
| + Namespace |
| + Classes |
|
◆ ------->
0 * |
| Class |
| + Attributes |
| + Comments |
| + Fields |
|
◆ ------->
0 * |
| Field |
| + Name |
| + Datatype |
| + Mappingtype |
| + Allownull |
| ...... |
|
Classgenerator has three special attributes: selectedclasses, save, and load. they make no sense. They only use the editorattribute they mark to execute multiple tables selected at a time using schemaexplorer, save the edited content as XML and load the content from XML.
Source code and template
BTW: I encountered a problem when using xtragrid. When I delete a column, the selected column will jump back. The result is that when I delete the last column, the index will be out of the range, who knows how to solve it?