gpt4 book ai didi

c# - PluralizationServices 将 Status 更改为 Statu

转载 作者:太空狗 更新时间:2023-10-29 18:00:00 24 4
gpt4 key购买 nike

我们有一个使用 System.Data.Entity.Design.PluralizationServices 的 T4 模板来处理某些模型生成的表名。

当我们运行名称中包含Status 的表时,例如CompanyStatusSingularize 方法返回CompanyStatu。我在下面有一些示例代码。

如何让它正确查看 CompanyStatus?

void Main()
{
// Sanity checks
Console.WriteLine(Singularize("Cats"));
Console.WriteLine(Singularize("Cat"));
Console.WriteLine(Singularize("Status"));
// The real issue
Console.WriteLine(Singularize("CompanyStatus"));
}

static string Singularize(string word)
{
var singularword = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(System.Globalization.CultureInfo.GetCultureInfo("en-us")).Singularize(word);
return singularword;
}

返回:

Cat
Cat
Status
CompanyStatu

我也试过:

static string Singularize(string word)
{
var pluralizationService = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
((ICustomPluralizationMapping)pluralizationService).AddWord("companystatus", "companystatuses");
var singularword = pluralizationService.Singularize(word);
return singularword;
}

最佳答案

Humanizer如果可以的话,会开箱即用吗?

// Note that you have to set the "inputIsKnownToBePlural" flag to false,
// or it will behave the same as PluralizationServices.

Console.WriteLine("Statuses".Singularize(inputIsKnownToBePlural: false));
Console.WriteLine("Status".Singularize(inputIsKnownToBePlural: false));
Console.WriteLine("CompanyStatus".Singularize(inputIsKnownToBePlural: false));
Console.WriteLine("CompanyStatuses".Singularize(inputIsKnownToBePlural: false));

Documentation .

关于c# - PluralizationServices 将 Status 更改为 Statu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41448588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com