DataUml Design 代码模板全然基于C#语言来编写的。

不懂写模板的能够请教作者,随时欢迎。

以下是一段模板代码,这段代码能够获取一个类结构的全部信息。

            <#@ template language="C#" HostSpecific="True" #>

            <# 

            NetUmlTemplateCodeHost host = (NetUmlTemplateCodeHost)(Host);

            #>

            命名空间:<#= host.ClassProperty.Namespace #>

            类名:<#= host.ClassProperty.ClassName #>

            类中文名:<#= host.ClassProperty.ClassOtherName #>

            表名:<#= host.ClassProperty.TableName #>

            可訪问性:<#= host.ClassProperty.Accessibility==null?"":host.ClassProperty.Accessibility #>

            修饰符:<#= host.ClassProperty.Modifier==null?"":host.ClassProperty.Modifier #>

            用户:<#= host.ClassProperty.User==null?

"":host.ClassProperty.User #> 

            备注:<#= host.ClassProperty.Remarks #>

            数据库类型:<#= host.ClassProperty.DataAccessType #>

            语言:<#= host.ClassProperty.ProjectLanage #>

            字段:

            <# foreach(var f in host.ClassProperty.Fields)

            {

                WriteLine("    属性名:"+f.PropertyName);

                WriteLine("    属性别名:"+f.PropertyOtherName);

                WriteLine("    属性类型:"+f.DataType);

                WriteLine("    修饰符:"+f.Modifier);

                WriteLine("    可訪问性:"+f.Accessibility);

                WriteLine("    是否空类型:"+f.IsNullType);

                WriteLine("    初始值:"+f.InitialValue);

                WriteLine("    是否仅仅读:"+f.IsReadable);

                WriteLine("    是否可写:"+f.IsWritable);

                WriteLine("    字段名:"+f.FieldName);

                WriteLine("    字段类型:"+f.FieldType);

                WriteLine("    长度:"+f.FieldLength);

                WriteLine("    是否为空:"+f.IsNull);

                WriteLine("    是否主键:"+f.IsPrimaryKey);

                if(f.IsPrimaryKey)

                {

                    WriteLine("    主键类型:"+f.PrimaryKeyType);

                }

                WriteLine("    是否外键:"+f.IsForeignKey);

                WriteLine("    默认值:"+f.DefaultValue);

                WriteLine("    备注信息:"+f.Remarks);

                )

                {

                    WriteLine("    属性:");

                    foreach(var p in f.Attributes)

                    {

                     WriteLine("        属性名:"+p.AttributeName);

                     WriteLine("        属性值:"+p.AttributeValue);

                    }

                }

                WriteLine("    ----------------");

            }

            #>



            类成员:



            表键信息:

            <# foreach(var k in host.ClassProperty.FieldKeyPropertys)

            {

                WriteLine(" 键名:"+k.KeyName);

                WriteLine(" 键类型:"+k.KeyType);

                WriteLine(" 字段:"+k.KeyFieldName);

                WriteLine(" 字段别名:"+k.KeyFieldOtherName);

                if(k.KeyType==KeyType.FOREIGN_KEY)

                {

                      WriteLine(" 约束名:"+k.ConstraintName);

                      WriteLine(" 约束表名:"+k.ConstraintTable);

                      WriteLine(" 约束表别名:"+k.ConstraintTableOtherName);

                      WriteLine(" 约束字段:"+k.ConstraintFields);

                      WriteLine(" 约束字段别名:"+k.ConstraintFieldsOtherName);      

                }

                WriteLine("----------------");

            }

            #>



            关联的类信息:

            <# foreach(RelationClass c in host.ClassProperty.RelationClasss)

            {

                WriteLine(" 关联类名:"+c.ClassProperty.ClassName);

                WriteLine(" 关联名称:"+c.RelationName);

                WriteLine(" 关联类型:"+c.TableRelationType);

                WriteLine(" UML关联类型:"+c.UmlRelationType);

                WriteLine(" IsConnectionLineStart:"+c.IsConnectionLineStart);

                WriteLine(" IsConnectionLineEnd:"+c.IsConnectionLineEnd);

                foreach(var f in c.RelationFields)

                {

                    ]+]);        

                }

                ]+]);

                WriteLine(    "----------------");

            }

            #> 

解说

            <#@ template language="C#" HostSpecific="True" #>

            <# 

            NetUmlTemplateCodeHost host = (NetUmlTemplateCodeHost)(Host);

            #>

            这段代码是必须的,它申明模板是採用哪种语言。

在模板里能够全然訪问NetUmlTemplateCodeHost
类里面的信息。这个类里面有个属性ClassProperty,这个属性包含模型中一个类的全部信息。

          <#  #>
全部语法代码都在这个符号里写

          host.ClassProperty.Fields中Fields属性是个集合,它包含全部字段信息

          以下是循环一个类中全部字段 

          <# foreach(var f in host.ClassProperty.Fields)

          {

          }

           #>

DataUml Design 教程5-代码模板介绍(甚于T4模板技术)的更多相关文章

  1. DataUml Design 教程4-代码生成

            DataUml Design 生成代码非常灵活,它是基于模板形式生成代码,如果不懂类结构的话写模型就比较困难了.这里我只讲解下如何生成代码,代码模板规则下一节将介绍.        1 ...

  2. DataUml Design 教程6-DataUML Design 1.1版本号正式公布(支持PD数据模型)

    从DataUML Design正式公布到如今有两个月了.因为近期比較忙,到如今才公布1.1版本号. 以后本人会一直坚持不断完好DataUML Design软件,希望广大程序员们多多支持. 一.1.1版 ...

  3. DataUml Design 教程7 - 数据库生成模型

    DataUml Design支持数据库生成模型,并支持外键关系,能够根据外键自动生成类与类之间的关系. 目前DataUML Design支持MS Server.MY SQL.Oracle和Access ...

  4. DataUml Design 教程6-DataUML Design 1.1版本正式发布(支持PD数据模型)

    从DataUML Design正式发布到现在有两个月了,由于最近比较忙,到现在才发布1.1版本.以后本人会一直坚持不断完善DataUML Design软件,希望广大程序猿们多多支持. 一.1.1版本新 ...

  5. DataUml Design 教程1-初识

        DataUml Design 是面向开发人员使用的一个永久免费的软件,提高软件的开发效率和代码的规范度.它主要包括三大功能,数据模型.代码生成和UML建模,数据模型功能类似于PowerDesi ...

  6. DataUml Design 教程3-模型与数据库同步

    上一节我们已经建立好了数据模型,那么怎么让数据模型和数据库进行同步呢?模型同步到数据库非常简单,只需要模型绑定到数据库即可.DataUml Design目前支持和Oracle与MS Server数据库 ...

  7. DataUml Design 教程2-实体建模

    DataUml Design 实体建模基于UML类图标准来设计,支持一对一.一对多.多对多关联.模型与开发语言和数据库绑定.1.新建数据模型    1).选择“数据模型” 节点,点击鼠标右键,在菜单中 ...

  8. DataUml Design 介绍10 - DataUML 1.4版本功能(增加UML活动图和用例图)

    DataUml Design 1.4版本正式发布 1.解决软件自动关闭的问题 2.增加UML活动图和用例图功能 详细介绍稍后继续...........................

  9. DataUml Design 课程6-DataUML Design 1.1版本号正式宣布(支持PD数据模型)

    从DataUML Design正式宣布到现在两个月,因为最近忙,出版到现在为止1.1版本号.稍后我们将始终坚持以良好DataUML Design软件,我希望程序员有很多支持. 一.1.1新的和改进的版 ...

随机推荐

  1. poj3253 优先队列

    Farmer John wants to repair a small length of the fence around the pasture. He measures the fence an ...

  2. deepin linux下markdown实时预览

    # deepin linux下markdown实时预览 ## 参考文章------------------------------ [vim安装markdown插件](http://www.jians ...

  3. Nmap笔记本

    nmap -vv 192.168.1.100 -p1-65535 跑1-65535的端口并且设置对结果的详细输出 nmap -vv 192.168.1.1/8 -p 1433 --open 跑开放14 ...

  4. LeetCode 145 Binary Tree Postorder Traversal(二叉树的兴许遍历)+(二叉树、迭代)

    翻译 给定一个二叉树.返回其兴许遍历的节点的值. 比如: 给定二叉树为 {1. #, 2, 3} 1 \ 2 / 3 返回 [3, 2, 1] 备注:用递归是微不足道的,你能够用迭代来完毕它吗? 原文 ...

  5. Excel函数sumproduct应用案例-多条件求和

    作者:iamlaosong 越来越认为sumproduct这个函数实用,过去用sum组函数.改起来复制起来都麻烦,sumif在条件多的时候也认为不方便. 如今改用sumproduct函数,就简单多了. ...

  6. 使用randA()生成randB()

    randA()表示可以随机生成1--A的整数 rand7()生成rand5() int Rand5(){ int x = ~(1<<31); // max int while(x > ...

  7. 分析kube-proxy的iptables规则

    NodePort service 创建一个mysql的NodePort服务,对应两个pod实例,rc和service的配置如下: 1.rc配置 apiVersion: v1 kind: Replica ...

  8. Android 启动界面的实现(转载)

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  9. Web安全测试(一)-手工安全测试方法&修改建议

    常见问题 1.XSS(CrossSite Script)跨站脚本攻击 XSS(CrossSite Script)跨站脚本攻击.它指的是恶意攻击者往Web 页面里插入恶意 html代码,当用户浏览该页之 ...

  10. 基于虚拟数据的行人检测研究(Expecting the Unexpected: Training Detectors for Unusual Pedestrians with Adversarial Imposters)

    Paper Link : https://arxiv.org/pdf/1703.06283 Github: https://github.com/huangshiyu13/RPNplus 摘要: 这篇 ...