1. 程式人生 > >asp.net T4模板使用教程

asp.net T4模板使用教程

span 手機號 down esp mail lap pac download hide

1、T4 Editor安裝

T4:根據模板生成文件,例如model等

vs中默認t4模板編碼是沒有提示和高亮的,需使用以下插件,免費的

https://t4-editor.tangible-engineering.com/Download_T4Editor_Plus_ModelingTools.html

也可以在vs的“工具->擴展和更新”中搜索t4,然後下載

註意:安裝的時候請先關閉vs,然後再安裝

2、T4簡單使用

技術分享圖片

輸入一段t4代碼

技術分享圖片
<#@ template debug="false" hostspecific="false" language="
C#" #> <#@ assembly name="System.Core" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.Collections.Generic" #> <#@ output extension=".cs" #> using System; using System.Collections.Generic; using System.Linq;
using System.Text; namespace t4ceshi { public class User { /// <summary> /// 用戶ID /// </summary> public int UserID { get; set; } /// <summary> /// 用戶名 /// </summary> public string UserName { get; set; }
/// <summary> /// 密碼 /// </summary> public string Password { get; set; } /// <summary> /// Email /// </summary> public string Email { get; set; } /// <summary> /// 手機號 /// </summary> public string Mobile { get; set; } } }
View Code

輸入完成後保存就會自動生成一個類文件

技術分享圖片

3、T4 之根據數據庫生成model

T4:根據模板生成文件,例如model等

load

asp.net T4模板使用教程