linux cpu占用率如何看
289
2022-09-28
T4 反射实体模型生成代码(Demo)
1.新建一个T4 Script
<#@ template language="C#" debug="True" #><#@ output extension="cs" #><#@ Assembly Name="System.Core" #><#@ Assembly Name="$(SolutionDir)Demo.Tools\bin\Debug\Demo.Tools.dll" #><#@ import namespace="System.IO" #><#@ Import Namespace="System.Linq" #><#@ Import Namespace="System.Text" #><#@ import namespace="System.Reflection" #><#@ Import Namespace="System.Collections.Generic" #><#@ Import Namespace="Demo.Tools" #><#@ include file="T4Toolbox.tt" #><#@ include file="EntityTemplate.tt" #><# //脚本运行路径 string currentPath = Path.GetDirectoryName(Host.TemplateFile); //解决方案路径 string solutionPath = currentPath.Substring(0, currentPath.IndexOf(@"\Demo.T4Generator\T4")); //输入文件路径 string outputPath = Path.Combine(solutionPath, @"MvcApplication1\Models"); //输出项目路径 string targetProject = Path.Combine(solutionPath, @"MvcApplication1\MvcApplication1.csproj"); //包含实体定义的DLL所在位置 string modelFile= Path.Combine(solutionPath, @"Demo.Entitys\bin\Debug\Demo.Entitys.dll"); //加载实体程序集 byte[] fileData= File.ReadAllBytes(modelFile); Assembly assembly = Assembly.Load(fileData); //反射出所有继承了Entity的实体类 IEnumerable
2、新建T4 Template,这里是具体的模板
<#+public class EntityConfigurationTemplate : CSharpTemplate{ private T4ModelInfo _model; public EntityConfigurationTemplate(T4ModelInfo model) { _model = model; } ///
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~