骆驼大小写中的 T4 FieldName 没有下划线? [英] T4 FieldName in camelCase without Underscore?

查看:52
本文介绍了骆驼大小写中的 T4 FieldName 没有下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 T4 生成一些类定义,并发现我的字段名称前面有一个下划线.

I'm using T4 to generate some class definitions and find that I'm getting an underscore in front of my field names.

我已经设置了

code.CamelCaseFields = true;

为了安全起见(尽管我知道这是默认设置)但最终仍然是 _myField 而不是 myField.

just to be safe (even though I understand that's the default) but still end up with _myField rather than myField.

如何生成不含_"字符的字段名称?

How can I generate a field name without the '_' character?

另外,T4 的文档在哪里?我找到了很多资源,例如

Also, where is the documentation for T4? I'm finding plenty of resources such as

代码生成和文本模板 和许多博客,但我还没有找到逐个类、逐个属性的文档.

Code Generation and Text Templates and numerous blogs, but I have not found the class-by-class, property-by-property documentation.

推荐答案

您可能在谈论 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.

这篇关于骆驼大小写中的 T4 FieldName 没有下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆