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;

  • 相关阅读:
    Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。
    [Pulgin] jQuery插件之ajaxFileUpload
    [Plugin] JQuery.uploadify上传文件插件的使用详解For ASP.NET
    [Plugin] 文件上传利器SWFUpload使用指南
    [HTML] 微信开发之移动手机WEB页面(HTML5)Javascript实现一键拨号及短信发送功能
    [JavaEE] IBM
    [TB-Technology] 淘宝在数据处理领域的项目及开源产品介绍
    [Hacker] 端口大全
    [.Net] DataTable添加列和行的三种方法
    [.Net] 导出Excel中身份证等数字串的解决方式
  • 原文地址:https://www.cnblogs.com/cdaq/p/4467583.html
Copyright © 2011-2022 走看看