zoukankan      html  css  js  c++  java
  • t4模板的认识

    1
    输出类
    <#=codeStringGenerator.EntityClassOpening(entity)#>

    public string EntityClassOpening(EntityType entity)
    {
    return string.Format(
    CultureInfo.InvariantCulture,
    "{0} {1}partial class {2}View{3}",// public partial class sysFunction
    Accessibility.ForType(entity),
    _code.SpaceAfter(_code.AbstractOption(entity)),
    _code.Escape(entity),
    _code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType)));
    }

    2 构造函数

    public <#=code.Escape(entity)#>()
    {
    <#
    foreach (var edmProperty in propertiesWithDefaultValues)
    {
    #>
    this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>;
    <#
    }

    foreach (var navigationProperty in collectionNavigationProperties)
    {
    #>
    this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName
    (navigationProperty.ToEndMember.GetEntityType())#>>();
    <#
    }

    foreach (var complexProperty in complexProperties)
    {
    #>
    this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>();
    <#
    }
    #>
    }

    3 命名空间
    <#=codeStringGenerator.UsingDirectives(inHeader: false)#>

    using Model;


    /// <summary>
    /// 数据层
    /// 成东
    /// </summary>

    <#=codeStringGenerator.EntityClassOpening(entity)#>


    4生成属性

    <#=codeStringGenerator.EntityClassOpening(entity)#>
    {

    #region 此表的特殊操作

    #endregion


    <#
    var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(entity);
    var collectionNavigationProperties = typeMapper.GetCollectionNavigationProperties(entity);
    var complexProperties = typeMapper.GetComplexProperties(entity);

    if (propertiesWithDefaultValues.Any() || collectionNavigationProperties.Any() || complexProperties.Any())
    {
    #>

    <#
    }

    var simpleProperties = typeMapper.GetSimpleProperties(entity);
    if (simpleProperties.Any())
    {
    foreach (var edmProperty in simpleProperties)
    {
    #>
    <#=codeStringGenerator.Property(edmProperty)#>
    <#
    }
    }

    if (complexProperties.Any())
    {
    #>

    <#
    foreach(var complexProperty in complexProperties)
    {
    #>
    <#=codeStringGenerator.Property(complexProperty)#>
    <#
    }
    }

    var navigationProperties = typeMapper.GetNavigationProperties(entity);
    if (navigationProperties.Any())
    {
    #>

    <#
    foreach (var navigationProperty in navigationProperties)
    {
    #>
    <#=codeStringGenerator.NavigationProperty(navigationProperty)#>
    <#
    }
    }
    #>


    }


    4 生成引用
    <#=codeStringGenerator.UsingDirectives(inHeader: false)#>
    下面我们可以自己加别的引用
    using System;

  • 相关阅读:
    命令提示符窗口adb shell 执行sqlite命令时进入 ...> 状态如何退出
    通过android studio 浏览模拟器中文件
    vim快捷键参考
    快速体验openstack-用devstack安装openstack
    css靠左,靠右
    全国-城市-百度地图中心点坐标
    java_dom4j解析xml
    December 31st, Week 53rd Tuesday, 2019
    December 28th, Week 52nd Saturday, 2019
    December 21st, Week 51st Saturday, 2019
  • 原文地址:https://www.cnblogs.com/cdaq/p/4467583.html
Copyright © 2011-2022 走看看