且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

骆驼大小写中的 T4 FieldName 没有下划线?

更新时间:2023-02-15 18:21:10

您可能在谈论 EF4 自我跟踪实体.CodeGenerationTools 类通过 <#@ include file="EF.Utility.CS.ttinclude"#> 指令包含,您可以在[VSInstallDir]\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.CS.ttinclude".

You're probably talking about EF4 Self Tracking Entities. The CodeGenerationTools class is included via the <#@ include file="EF.Utility.CS.ttinclude"#> directive, which you can find at "[VSInstallDir]\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.CS.ttinclude".

FieldName 函数定义如下:

The FieldName function is defined as such:

private string FieldName(string name)
{
  if (CamelCaseFields)
  {
    return "_" + CamelCase(name);
  }
  else
  {
    return "_" + name;
  }
}

_"在函数中是硬编码的.自己编写代码应该不难.请注意,CodeGenerationTools 类特定于此 ttinclude 文件,并不是在 T4 中生成代码的通用和嵌入式方式.

The "_" is hardcoded in the function. Coding your own shouldn't be difficult. Note that the CodeGenerationTools class is specific to this ttinclude file and isn't a generic and embedded way to generate code in T4.