| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <#@ 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\IUnitOfWorkTemplate.ttinclude" #>
- <#
- // <copyright file="BllCodeScript.tt" company="Yue@China">
- // Copyright © . All Rights Reserved.
- // </copyright>
- //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<System.Attribute[], bool> 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<T4ModelInfo> modelList= new List<T4ModelInfo>();
- foreach(Type modelType in modelTypes)
- {
- T4ModelInfo model = new T4ModelInfo(modelType);
- modelList.Add(model);
- }
- T4ModelInfo[] models=modelList.ToArray();;
- //实体映射类
- IUnitOfWorkTemplate config = new IUnitOfWorkTemplate(models);
- string path = string.Format(@"{0}/Interface", projectPath);
- config.Output.Encoding = Encoding.UTF8;
- config.RenderToFile(Path.Combine(path, config.FileName));
-
- #>
|