代码生成的字符串实用程序库

时间:2022-03-22 07:42:18

CodeSmith has a nice StringUtils class that can be used to change database object names to singular, plural, camel case, pascal case, etc... Very useful for creating data access layers in their code generation tool.

CodeSmith有一个很好的StringUtils类,可用于将数据库对象名称更改为单数,复数,驼峰大小写,pascal大小写等等。在代码生成工具中创建数据访问层非常有用。

I'm trying to port some CodeSmith templates to the T4 template files used by Visual Studio, and I'm trying to find a similar library to do these things.

我正在尝试将一些CodeSmith模板移植到Visual Studio使用的T4模板文件,我正在尝试找到类似的库来执行这些操作。

There must be one somewhere in T4, since that's what is used to produce the LINQ to SQL classes, and it does a nice job of pluralization / singularization.

在T4中必须有一个,因为那是用于生成LINQ to SQL类的东西,并且它在多元化/单一化方面做得很好。

Does anyone know where this library exists, or if a free library with similar functionality exists somewhere?

有谁知道这个库的存在位置,或者某个地方是否存在具有类似功能的免费库?

1 个解决方案

#1


I've used both CodeSmith with .netTiers, and more recently T4. I'm not sure as to the specifics of what Linq to SQL uses, but with T4 you can basically do anything you can do in code in the .NET framework.

我已经将CodeSmith与.netTiers以及最近的T4一起使用。我不确定Linq to SQL使用的具体细节,但是使用T4,您基本上可以在.NET框架中的代码中执行任何操作。

To that end, why not craft you own StringUtils class (there are plenty of existing, open source projects that provide numerous pre-written method libs), and include these utilities in a external T4 file. You can then include this file as a parent to the child template you are creating. You can use the include directive to do this, like so:

为此,为什么不制作自己的StringUtils类(有很多现有的开源项目提供了大量预先编写的方法库),并将这些实用程序包含在外部T4文件中。然后,您可以将此文件包含为要创建的子模板的父文件。您可以使用include指令执行此操作,如下所示:

<#@ include file="Utilities.tt" #>

#1


I've used both CodeSmith with .netTiers, and more recently T4. I'm not sure as to the specifics of what Linq to SQL uses, but with T4 you can basically do anything you can do in code in the .NET framework.

我已经将CodeSmith与.netTiers以及最近的T4一起使用。我不确定Linq to SQL使用的具体细节,但是使用T4,您基本上可以在.NET框架中的代码中执行任何操作。

To that end, why not craft you own StringUtils class (there are plenty of existing, open source projects that provide numerous pre-written method libs), and include these utilities in a external T4 file. You can then include this file as a parent to the child template you are creating. You can use the include directive to do this, like so:

为此,为什么不制作自己的StringUtils类(有很多现有的开源项目提供了大量预先编写的方法库),并将这些实用程序包含在外部T4文件中。然后,您可以将此文件包含为要创建的子模板的父文件。您可以使用include指令执行此操作,如下所示:

<#@ include file="Utilities.tt" #>