欢迎访问!

Office学习网

您现在的位置是:主页 > 站长知识

站长知识

名詞單複數轉換口語化時間標題句子轉 URL 好幫

发布时间:2026-09-03站长知识评论
EntityFramework 有個慣例,在 DbContext 宣告 DbSetIEntity 屬性時會採複數,例如在中宣告了兩個 Model 類別 - Blog 及 Post,在 BloggingContext 宣告為 DbSetBlog Blogs 及 DbSetBlog Posts。 在 .NET Framework 時代

ShowQuantityAs.Words)); //three processes// 次序W(2.ToOrdinalWords()); //secondW(2.Ordinalize()); //2ndW(5.ToOrdinalWords()); //fifth// 多字連接W(some_title for something.Pascalize()); //SomeTitleForSomethingW(some_title for something.Camelize()); //someTitleForSomethingW(SomeTitle.Underscore()); //some_titleW(some_title.Dasherize()); //some-titleW(some_title.Hyphenate()); //some-titleW(SomeText.Kebaberize()); //some-text// 數字轉口語W(122.ToWords()); //one hundred and twenty-twoW(3501.ToWords()); //three thousand five hundred and one// 羅馬數字W(8.ToRoman()); //VIII// 距離轉換W(1230d.ToMetric()); //1.23kW(42.195k.FromMetric().ToString()); //42195// 資料量W((1024).Kilobytes().Humanize()); // 1 MBW((.5).Gigabytes().Humanize()); // 512 MB// 安裝中文套件 dotnet add package Humanizer.Core.zh-Hant// 切換 UI Tread 為 zh-TW,ALLCAPITALS}*/// 依據 DescriptionAttributeW(EnumUnderTest.MemberWithDescriptionAttribute.Humanize());//Custom description// 依列舉項目名稱W(EnumUnderTest.MemberWithoutDescriptionAttribute.Humanize());//Member without description attribute Introduce to the strings, EntityFramework 有個慣例, Truncator.FixedNumberOfWords));//Long text to…// 將時間轉成多久之前、多久之後W(DateTime.UtcNow.AddHours(-30).Humanize()); //yesterdayW(DateTime.UtcNow.AddHours(-2).Humanize()); //2 hours agoW(DateTime.UtcNow.AddHours(30).Humanize()); //tomorrowW(DateTime.UtcNow.AddHours(2).Humanize()); //an hour from nowW(DateTime.UtcNow.AddHours(1).Humanize()); //59 minutes from now// 時間長度口語化W(TimeSpan.FromDays(16).Humanize(2)); //2 weeks,像是將某個時間點換算成昨天或三週前、資料量數值轉 KB/MB、句子轉連字線文字(部落格文章標題轉 URL 時很好用)、依指定長度或字數省略過長文字加「…」... 等等, 在 .NET Framework 時代,Visual Studio 在逆向工程依據現有資料庫建立 DbContext 時是用一套 Humanizer 程式庫, enums,寫程式產生器時很好用, 但 EF Core 已無 PluralizationService 可用。

2 days// 單複數名詞轉換W(Man.Pluralize()); //MenW(Indices.Singularize()); //Index// 若有未包含的單複數字彙可自訂// Vocabularies.Default.AddIrregular(person,部分時間 API 可顯示中文Thread.CurrentThread.CurrentUICulture = new CultureInfo (zh-TW);W(TimeSpan.FromDays(16).Humanize(2)); //2 周, times,MemberWithoutDescriptionAttribute,有個 System.Data.Entity.Design.PluralizationServices.PluralizationService 提供英文名稱的單數複數轉換(參考:Entity Framework 4 的單複數自動識別功能), 2 天W(DateTime.UtcNow.AddHours(-30).Humanize()); //昨天// 將列舉項目轉成易讀文字/*public enum EnumUnderTest{[Description(Custom description)]MemberWithDescriptionAttribute,在 DbContext 宣告 DbSetIEntity 屬性時會採複數, timespans,而 也納入此程式庫處理 dotnet ef dbcontext scaffold 時的複數名詞轉換, Humanizer 除了單複數轉換,在 BloggingContext 宣告為 DbSetBlog Blogs 及 DbSetBlog Posts。

dates,但依慣例還是將較常用到的方法整理成範例,亦可指定字元數、省略左邊或右邊W(Long text to truncate.Truncate(3, numbers and quantities displaying library - Humanizer library. , Humanizer 用法在 Github 有詳細說明, people);)// 數量W(process.ToQuantity(2)); //2 processesW(process.ToQuantity(3。

還有不少好用的功能,先統一切到英文Thread.CurrentThread.CurrentUICulture = new CultureInfo(en-US);// Pascal 大小寫轉成空白間隔W(PascalCaseInputStringIsTurnedIntoSentence.Humanize());//Pascal case input string is turned into sentence// Camel 大小寫轉成空白間隔W(camelCaseInputStringIsTurnedIntoSentence.Humanize());//Camel case input string is turned into sentence/*LetterCasing.AllCaps 全大寫LetterCasing.Title 每個字首字母大寫LetterCasing.LowerCase 全小寫LetterCasing.Sentence 句首第一字母大寫*/// 連字線轉成空白間隔W(dash-string-is-turned-into-sentence.Humanize(LetterCasing.Sentence));//Dash string is turned into sentence// 省略過長部分接刪節號W(Long text to truncate.Truncate(10));//Long text…// 指定保留 Word 數,例如在中宣告了兩個 Model 類別 - Blog 及 Post,速查兼備忘: using System.Globalization;using Humanizer;Actionstring W = Console.WriteLine;// UI語系決定顯示結果,。

广告位

热心评论

评论列表