动软代码生成器 常用函数

 动软代码生成器在自动化生成.Net代码方面功能非常强大。在实际使用中,我也经常使用它的自定义模板功能,生成Js、html、php、java等代码。其模板里的函数与.net函数并不完全一致,现把模板常用代码写在这里,以方便查询使用。实际使用中每个项目要按自己框架情况进行定义。

<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".js" #>
<#
    TableHost host = (TableHost)(Host); 
    string DbParaHead=host.DbParaHead;
    string DbParaDbType=host.DbParaDbType;
    string preParameter=host.preParameter;
    string ModelSpace = host.NameSpace+".Model."+ host.GetModelClass(host.TableName);
    string TableName =  host.GetModelClass(host.TableName);
    string ModuleName = TableName;
    string ActionName = TableName;
    if(TableName.IndexOf('_') > -1){
        string[] tempArray=TableName.Split('_');
        ModuleName=tempArray[0];
        ActionName=tempArray[1];
        if(tempArray.Length==3)ActionName += "_"+tempArray[2];
    }   
    ColumnInfo identityKey=host.IdentityKey;
    string returnValue = "void";
    if (identityKey!=null)
    {         
        returnValue = CodeCommon.DbTypeToCS(identityKey.TypeName);              
    }else if(2>1){
    }
    else{
        identityKey=host.Fieldlist[0];
    }
#>
  • 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

字符串函数

String Abc=actionArr[2].Substring(0,1).ToUpper() + actionArr[2].Substring(1,actionArr[2].Length-1);
"CABc".ToLower()
  • 1
  • 2

字段遍历

<# for(int i=0;i< host.Fieldlist.Count;i++){
 ColumnInfo c = host.Fieldlist[i];
 //c.ColumnName   字段名称
 //CodeCommon.DbTypeToCS(c.TypeName)  字段类型
 //c.Length 字段长度
  String type=CodeCommon.DbTypeToCS(c.TypeName);
  if(type=="DateTime")type="String";
  else if(type=="int")type="Integer";
  else if(type=="string")type="String";
  else if(type=="decimal")type="Float";
#>
<#}#>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

字段类型枚举:

CodeCommon.DbTypeToCS(c.TypeName)

  • DateTime
  • int
  • Boolean
  • string
  • decimal
版权声明:(谢厂节的博客)博主文章绝大部分非原创,转载望留链接。 https://blog.csdn.net/xundh/article/details/46581165

猜你喜欢

转载自blog.csdn.net/qq285679784/article/details/80331890