zoukankan      html  css  js  c++  java
  • T4 模板生产 多文件

     借鉴 EF 生成实体的方法,
    1
    <#@ template language="C#" debug="false" hostspecific="true"#> 2 <#@ include file="EF.Utility.CS.ttinclude"#><#@ 3 output extension=".cs"#> 4 5 <# 6 7 CodeGenerationTools code = new CodeGenerationTools(this); 8 MetadataLoader loader = new MetadataLoader(this); 9 CodeRegion region = new CodeRegion(this, 1); 10 MetadataTools ef = new MetadataTools(this); 11 12 string inputFile = @"E:YC969.MVC42017.11.13内容CodeDirect.YC96.ModelsMyFrameDBModels.edmx"; 13 14 EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile); 15 string namespaceName = code.VsNamespaceSuggestion(); 16 17 EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); 18 19 #> 20 <# 21 // Emit Entity Types 22 foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name)) 23 { 24 fileManager.StartNewFile("文件名.cs");// 创建文件 名 25 #> 26 //类文件代码 27 using System; 28 using System.Collections.Generic; 29 using System.Linq; 30 using System.Linq.Expressions; 31 using System.Text; 32 using System.Threading.Tasks; 33 34 namespace 命名空间 35 { 36 37 //BeginNamespace(namespaceName, code); 38 39 public interface I<#=entity.Name#>DAL:IBaseDAL<<#=entity.Name#>> 40 { 41 42 } 43 44 } 45 <# 46 47 48 } 49 fileManager.Process();// 调用生成文件的 方法 50 #> 51 52 53 54
  • 相关阅读:
    bzoj1453
    276D
    855E
    bzoj1458
    树莓派 自启动连接阿里云物联网平台(一)
    树莓派 实现脚本程序自启动
    树莓派4B 系统镜像安装与boot配置
    2019-2020-2《网络对抗技术》 Exp1 PC平台逆向破解
    2019-2020-2 《网络对抗技术》 Exp0 kali 安装
    kali 添加使用 KDE 桌面环境
  • 原文地址:https://www.cnblogs.com/askmeqq/p/7831439.html
Copyright © 2011-2022 走看看