When a soft code generator generates an object, modify the template to simplify entity encapsulation. The Code Generator entity

Source: Internet
Author: User

When a soft code generator generates an object, modify the template to simplify entity encapsulation. The Code Generator entity

First, right-click the Code Template and choose create template.

<# @ Template language = "c #" HostSpecific = "True" #> <# @ output extension = ". cs "#> <# TableHost host = (TableHost) (Host); host. fieldlist. sort (CodeCommon. compareByintOrder); #> using System; using System. text; using System. collections. generic; using System. data; namespace <# = host. nameSpace #>. model <# if (host. folder. length> 0) {#>. <# = host. folder #> <#}#>{< # if (host. tableDescription. length> 0) {#>// <# = Host. tableDescription #> <#}#> public class <# = host. getModelClass (host. tableName) # >{< # foreach (ColumnInfo c in host. fieldlist) {#>/// <summary> /// <# = string. isNullOrEmpty (c. description )? C. columnName: c. description #> // </summary> public <# = GetTypeName (c) #> <# = c. columnName #>{ get; set ;}###>}< # + private string GetTypeName (ColumnInfo c)
{
If (CodeCommon. DbTypeToCS (c. TypeName). ToString (). Trim (). ToLower ())! = "String") // if the field can be empty and cannot be converted to an empty string
{

Return CodeCommon. DbTypeToCS (c. TypeName) + "? ";
}

Else
{
Return CodeCommon. DbTypeToCS (c. TypeName );
}

} #>

Paste and save the code.

 

 

Usage:

1. Click the template we just created

2. Click Generate code.

The generated code is like this.

Public class User_Users {// <summary>
/// UserId
/// </Summary>
Public int? UserId {get; set ;}
/// <Summary>
/// Employee name
/// </Summary>
Public string UserName {get; set ;}
/// <Summary>
/// English name
/// </Summary>
Public string EnglishName {get; set ;}
/// <Summary>
/// Password
/// </Summary>
Public string PassWord {get; set ;}
/// <Summary>
/// Employee ID
/// </Summary>
Public string JobNumber {get; set ;}
/// <Summary>
/// Position
/// </Summary>
Public string Position {get; set ;}}

 

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.