<#@ template language="C#" debug="True" #> <#@ output extension="cs" #> <#@ Assembly Name="System.Core" #> <#@ Assembly Name="$(SolutionDir)\T4\bin\Debug\T4.dll" #> <#@ import Namespace="System.IO" #> <#@ Import Namespace="System.Linq" #> <#@ Import Namespace="System.Text" #> <#@ import Namespace="System.Reflection" #> <#@ Import Namespace="System.Collections.Generic" #> <#@ Import Namespace="T4" #> <#@ include file="T4Toolbox.tt" #> <#@ include file="..\..\T4\Include\UnitOfWorkTemplate.ttinclude" #> <# // // Copyright © . All Rights Reserved. // //System.Diagnostics.Debugger.Launch(); //模版调试第一个断点 //System.Diagnostics.Debugger.Break(); //模版调试断点 string currentPath=Path.GetDirectoryName(Host.TemplateFile); string projectPath =currentPath.Substring(0, currentPath.IndexOf(@"\T4")); string solutionPath = currentPath.Substring(0, currentPath.IndexOf(@"\YZXYH2017")); string modelFile= Path.Combine(solutionPath, @"YZXYH2017\YZXYH.Repository\bin\Debug\YZXYH.Repository.dll"); byte[] fileData= File.ReadAllBytes(modelFile); Assembly assembly=Assembly.Load(fileData); Type[] allModelTypes=assembly.GetTypes(); Func IsSerial = o => { foreach (System.Attribute a in o) { if (a is SerializableAttribute) return true; } return false; }; Type[] modelTypes=allModelTypes.Where(o=> { return IsSerial(System.Attribute.GetCustomAttributes(o, true)); }).ToArray(); List modelList= new List(); foreach(Type modelType in modelTypes) { T4ModelInfo model = new T4ModelInfo(modelType); modelList.Add(model); } T4ModelInfo[] models=modelList.ToArray();; //实体映射类 UnitOfWorkTemplate config = new UnitOfWorkTemplate(models); string path = string.Format(@"{0}", projectPath); config.Output.Encoding = Encoding.UTF8; config.RenderToFile(Path.Combine(path, config.FileName)); #>