CodeSmith - 產生 Auto-Implemented Properties 的範本

CodeSmith - 產生 Auto-Implemented Properties 的範本

參考【CodeSmith - 快速產生欄位 (Field) 與屬性 (Property)】文章,改寫 Code Smith 範本讀取 DataTable 自動產生類別中的 Auto-Implemented Properties 屬性。

範本 .cst 檔案內容:

   1:  <%-- 
   2:  Name: Database Table Auto-Implemented Properties 
   3:  Author: C.H.Huang
   4:  Description: Create a list of auto-implemented properties from a database table
   5:  --%>
   6:  <%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
   7:  <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
   8:  <%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
   9:  <%@ Assembly Name="SchemaExplorer" %>
  10:  <%@ Import Namespace="SchemaExplorer" %>
  11:   
  12:  #region 屬性
  13:   
  14:  <% foreach (ColumnSchema column in this.SourceTable.Columns) %>
  15:  <% {  %>
  16:  /// <summary>
  17:  /// <%= column.Description %>
  18:  /// </summary>
  19:  public <%= CSharpAlias[column.SystemType.FullName] %> <%= StringUtil.ToPascalCase(column.Name) %> { get; set; }
  20:   
  21:  <% } %>
  22:  #endregion

範例資料庫 Schema:

CodeSmith001

產生的程式範例碼:

CodeSmith002