2022.0116-beta1
大石头 authored at 2022-01-16 18:18:02
1.76 KiB
X
<#@ template language="C#" hostSpecific="true" debug="true" #>
<#@ assembly name="netstandard" #>
<#@ assembly name="$(SolutionDir)\DLL\NewLife.Core.dll" #>
<#@ assembly name="$(SolutionDir)\DLL\XCode.dll" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="XCode.Code" #>
<#@ import namespace="XCode.DataAccessLayer" #>
<#@ output extension=".log" #>
<#
    // XCode代码生成模板用法: https://www.yuque.com/smartstone/xcode/model

    // 设置当前工作目录
	PathHelper.BasePath = Host.ResolvePath(".");

    // 设置如何格式化字段名,默认去掉下划线并转驼峰命名
    //ModelResolver.Current = new ModelResolver { TrimUnderline = false, Camel = false };

    // 加载模型文件,得到数据表
    var option = new BuilderOption();
    var tables = ClassBuilder.LoadModels(null, option, out var atts);
    EntityBuilder.FixModelFile(null, option, atts, tables);

    // 生成实体类
    //option.BaseClass = "I{name}";
    //option.ModelNameForCopy = "I{name}";
    EntityBuilder.BuildTables(tables, option, chineseFileName: true);

    // 生成简易模型类
    option.Output = @"Output\EntityModels\";
    option.ClassNameTemplate = "{name}Model";
    option.ModelNameForCopy = "I{name}";
    //ClassBuilder.BuildModels(tables, option);

    // 生成简易接口
    option.BaseClass = null;
    option.ClassNameTemplate = null;
    option.Output = @"Output\EntityInterfaces\";
    //ClassBuilder.BuildInterfaces(tables, option);

    // 精确控制生成
    /*foreach (var item in tables)
    {
        var builder = new ClassBuilder
        {
            Table = item,
            Option = option.Clone(),
        };
        builder.Execute();
        builder.Save(null, true, false);
    }*/
#>