From f731b8db7e28ca8d931a917b6aadae6a3cd779de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20ANDRE=20=28E104915=29?= Date: Sat, 21 Dec 2024 06:54:30 +0100 Subject: [PATCH] feat: Support net9.0, update packages, and refactor code Updated Directory.build.props to support net9.0 alongside net8.0. Introduced conditional compilation in DateTimeHumanize.cs for System.Threading and Lock object usage in .NET 9.0 or greater. Updated MyNet.Humanizer.UnitTests.csproj with newer versions of Microsoft.NET.Test.Sdk (17.12.0), xunit (2.9.2), and xunit.runner.visualstudio (3.0.0). Updated MyNet.Humanizer.csproj t reference MyNet.Utilities version 6.0.0, up from 5.0.0. BREAKING CHANGE: Support net9.0 --- src/Directory.build.props | 2 +- src/MyNet.Humanizer.UnitTests/DateTimeHumanize.cs | 8 ++++++++ src/MyNet.Humanizer.UnitTests/InflectorExtensionsTests.cs | 2 ++ .../MyNet.Humanizer.UnitTests.csproj | 6 +++--- src/MyNet.Humanizer/MyNet.Humanizer.csproj | 2 +- src/MyNet.Humanizer/TimeSpanHumanizeExtensions.cs | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Directory.build.props b/src/Directory.build.props index d94ed23..1c5698c 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -12,7 +12,7 @@ - net8.0 + net8.0;net9.0 bin true Release diff --git a/src/MyNet.Humanizer.UnitTests/DateTimeHumanize.cs b/src/MyNet.Humanizer.UnitTests/DateTimeHumanize.cs index 529843c..9963913 100644 --- a/src/MyNet.Humanizer.UnitTests/DateTimeHumanize.cs +++ b/src/MyNet.Humanizer.UnitTests/DateTimeHumanize.cs @@ -7,11 +7,19 @@ using MyNet.Humanizer.DateTimes; using Xunit; +#if NET9_0_OR_GREATER +using System.Threading; +#endif + namespace MyNet.Humanizer.UnitTests { public static class DateTimeHumanize { +#if NET9_0_OR_GREATER + private static readonly Lock LockObject = new(); +#else private static readonly object LockObject = new(); +#endif private static void VerifyWithCurrentDate(string expectedString, string expectedCultureName, TimeSpan deltaFromNow, CultureInfo? culture) { diff --git a/src/MyNet.Humanizer.UnitTests/InflectorExtensionsTests.cs b/src/MyNet.Humanizer.UnitTests/InflectorExtensionsTests.cs index 6519c84..6f46624 100644 --- a/src/MyNet.Humanizer.UnitTests/InflectorExtensionsTests.cs +++ b/src/MyNet.Humanizer.UnitTests/InflectorExtensionsTests.cs @@ -39,6 +39,7 @@ public void SingularizeWordsWithUnknownSingularity(string singular, string plura [Theory, UseCulture("fr-FR")] [ClassData(typeof(FrenchPluralTestSource))] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4144:Methods should not have identical implementations", Justification = "Culture changes")] public void PluralizeWordsWithUnknownPluralityFrench(string singular, string plural) { Assert.Equal(plural, plural.Pluralize(false)); @@ -51,6 +52,7 @@ public void PluralizeWordsWithUnknownPluralityFrench(string singular, string plu [Theory, UseCulture("fr-FR")] [ClassData(typeof(FrenchPluralTestSource))] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4144:Methods should not have identical implementations", Justification = "Culture changes")] public void SingularizeWordsWithUnknownSingularityFrench(string singular, string plural) { Assert.Equal(singular, singular.Singularize(false)); diff --git a/src/MyNet.Humanizer.UnitTests/MyNet.Humanizer.UnitTests.csproj b/src/MyNet.Humanizer.UnitTests/MyNet.Humanizer.UnitTests.csproj index 5472352..95ef56a 100644 --- a/src/MyNet.Humanizer.UnitTests/MyNet.Humanizer.UnitTests.csproj +++ b/src/MyNet.Humanizer.UnitTests/MyNet.Humanizer.UnitTests.csproj @@ -5,9 +5,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MyNet.Humanizer/MyNet.Humanizer.csproj b/src/MyNet.Humanizer/MyNet.Humanizer.csproj index c1e7299..8b61413 100644 --- a/src/MyNet.Humanizer/MyNet.Humanizer.csproj +++ b/src/MyNet.Humanizer/MyNet.Humanizer.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/MyNet.Humanizer/TimeSpanHumanizeExtensions.cs b/src/MyNet.Humanizer/TimeSpanHumanizeExtensions.cs index fa4fdd3..c5c4153 100644 --- a/src/MyNet.Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/MyNet.Humanizer/TimeSpanHumanizeExtensions.cs @@ -79,7 +79,7 @@ private static List CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan t private static IEnumerable GetEnumTypesForTimeUnit() { - var enumTypeEnumerator = (IEnumerable)Enum.GetValues(typeof(TimeUnit)); + var enumTypeEnumerator = Enum.GetValues(); return enumTypeEnumerator.Reverse(); }