From 8c5af5ea9b2f9f1b1b5dd14aa33155f225c4f81d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 20:25:53 +1100 Subject: [PATCH 01/39] Update ArticlePrefixSort.cs --- src/Humanizer/ArticlePrefixSort.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Humanizer/ArticlePrefixSort.cs b/src/Humanizer/ArticlePrefixSort.cs index 4e6574898..a209b3e60 100644 --- a/src/Humanizer/ArticlePrefixSort.cs +++ b/src/Humanizer/ArticlePrefixSort.cs @@ -1,4 +1,6 @@ -namespace Humanizer +#nullable enable + +namespace Humanizer { /// /// Contains methods for removing, appending and prepending article prefixes for sorting strings ignoring the article. From cc4b5d3a028fb1ef53574dcb969acbc65164bf01 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 20:27:52 +1100 Subject: [PATCH 02/39] Update Benchmarks.csproj --- src/Benchmarks/Benchmarks.csproj | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Benchmarks/Benchmarks.csproj b/src/Benchmarks/Benchmarks.csproj index bcf7843ad..8f9f79f9e 100644 --- a/src/Benchmarks/Benchmarks.csproj +++ b/src/Benchmarks/Benchmarks.csproj @@ -1,14 +1,15 @@  - - Exe - net8.0 - + + Exe + net8.0 + enable + - - - + + + - + From b9d7db5e4c3b89d04e55c90f8c3ca4d8d2bda524 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 20:40:14 +1100 Subject: [PATCH 03/39] . --- .../Bytes/ByteRateTests.cs | 2 +- .../Bytes/ByteSizeExtensionsTests.cs | 12 ++++---- .../CollectionHumanizeTests.cs | 6 ++-- src/Humanizer.Tests.Shared/DateHumanize.cs | 10 +++---- .../Localisation/de/Bytes/ByteRateTests.cs | 2 +- .../de/Bytes/ByteSizeExtensionsTests.cs | 12 ++++---- .../fr/Bytes/ByteSizeExtensionsTests.cs | 12 ++++---- .../is/Bytes/ByteSizeExtensionsTests.cs | 12 ++++---- .../Localisation/lb/Bytes/ByteRateTests.cs | 2 +- .../lb/Bytes/ByteSizeExtensionsTests.cs | 12 ++++---- .../TimeSpanHumanizeTests.cs | 2 +- src/Humanizer.Tests.Shared/ToQuantityTests.cs | 2 +- src/Humanizer.Tests.Shared/TruncatorTests.cs | 28 +++++++++---------- .../UseCultureAttribute.cs | 8 +++--- src/Humanizer.Tests/Humanizer.Tests.csproj | 1 + 15 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs b/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs index 09f4938e6..5723f52e3 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs @@ -44,7 +44,7 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim [Theory] [InlineData(19854651984, 1, TimeUnit.Second, null, "18.49 GB/s")] [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18.49 GB/s")] - public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue) + public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string? format, string expectedValue) { var size = ByteSize.FromBytes(bytes); var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds); diff --git a/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs index 9ccd1c074..b5a0a3fe9 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs @@ -67,7 +67,7 @@ public void LongTerabytes() [InlineData(2.123, "#.#", "en", "2.1 TB")] [InlineData(2.1, null, "ru-RU", "2,1 TB")] [InlineData(2.123, "#.#", "ru-RU", "2,1 TB")] - public void HumanizesTerabytes(double input, string format, string cultureName, string expectedValue) + public void HumanizesTerabytes(double input, string? format, string cultureName, string expectedValue) { var culture = new CultureInfo(cultureName); @@ -137,7 +137,7 @@ public void LongGigabytes() [InlineData(2, null, "fr", "2 Go")] [InlineData(2, "MB", "en", "2048 MB")] [InlineData(2.123, "#.##", "en", "2.12 GB")] - public void HumanizesGigabytes(double input, string format, string cultureName, string expectedValue) + public void HumanizesGigabytes(double input, string? format, string cultureName, string expectedValue) { var cultureInfo = new CultureInfo(cultureName); @@ -207,7 +207,7 @@ public void LongMegabytes() [InlineData(2, null, "fr", "2 Mo")] [InlineData(2, "KB", "en", "2048 KB")] [InlineData(2.123, "#", "en", "2 MB")] - public void HumanizesMegabytes(double input, string format, string cultureName, string expectedValue) + public void HumanizesMegabytes(double input, string? format, string cultureName, string expectedValue) { var cultureInfo = new CultureInfo(cultureName); @@ -277,7 +277,7 @@ public void LongKilobytes() [InlineData(2, null, "fr", "2 Ko")] [InlineData(2, "B", "en", "2048 B")] [InlineData(2.123, "#.####", "en", "2.123 KB")] - public void HumanizesKilobytes(double input, string format, string cultureName, string expectedValue) + public void HumanizesKilobytes(double input, string? format, string cultureName, string expectedValue) { var cultureInfo = new CultureInfo(cultureName); @@ -352,7 +352,7 @@ public void LongBytes() [InlineData(10000000, "KB", "en", "9765.63 KB")] [InlineData(10000000, "#,##0 KB", "en", "9,766 KB")] [InlineData(10000000, "#,##0.# KB", "en", "9,765.6 KB")] - public void HumanizesBytes(double input, string format, string cultureName, string expectedValue) + public void HumanizesBytes(double input, string? format, string cultureName, string expectedValue) { var cultureInfo = new CultureInfo(cultureName); @@ -415,7 +415,7 @@ public void LongBits() [InlineData(2, null, "fr", "2 b")] [InlineData(12, "B", "en", "1.5 B")] [InlineData(10000, "#.# KB", "en", "1.2 KB")] - public void HumanizesBits(long input, string format, string cultureName, string expectedValue) + public void HumanizesBits(long input, string? format, string cultureName, string expectedValue) { var cultureInfo = new CultureInfo(cultureName); diff --git a/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs b/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs index 8fa0ab3ad..9d61fe828 100644 --- a/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs @@ -2,7 +2,7 @@ { public class SomeClass { - public string SomeString; + public string? SomeString; public int SomeInt; public override string ToString() => "ToString"; @@ -97,7 +97,7 @@ public void HumanizeUsesObjectDisplayFormatterWhenSeparatorIsProvided() [Fact] public void HumanizeHandlesNullItemsWithoutAnException() => - Assert.Null(Record.Exception(() => new object[] { null, null }.Humanize())); + Assert.Null(Record.Exception(() => new object?[] { null, null }.Humanize())); [Fact] public void HumanizeHandlesNullStringDisplayFormatterReturnsWithoutAnException() => @@ -105,7 +105,7 @@ public void HumanizeHandlesNullStringDisplayFormatterReturnsWithoutAnException() [Fact] public void HumanizeHandlesNullObjectDisplayFormatterReturnsWithoutAnException() => - Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => (object)null))); + Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => (object?)null))); [Fact] public void HumanizeRunsStringDisplayFormatterOnNulls() => diff --git a/src/Humanizer.Tests.Shared/DateHumanize.cs b/src/Humanizer.Tests.Shared/DateHumanize.cs index 73d6de32f..c06b91d6a 100644 --- a/src/Humanizer.Tests.Shared/DateHumanize.cs +++ b/src/Humanizer.Tests.Shared/DateHumanize.cs @@ -4,7 +4,7 @@ public class DateHumanize { static readonly object LockObject = new(); - static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow, CultureInfo culture) + static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow, CultureInfo? culture) { var utcNow = DateTime.UtcNow; var localNow = DateTime.Now; @@ -13,7 +13,7 @@ static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow, VerifyWithDate(expectedString, deltaFromNow, culture, localNow, utcNow); } - static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow, CultureInfo culture) + static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow, CultureInfo? culture) { var utcNow = new DateTime(2013, 6, 20, 9, 58, 22, DateTimeKind.Utc); var now = new DateTime(2013, 6, 20, 11, 58, 22, DateTimeKind.Local); @@ -21,7 +21,7 @@ static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow VerifyWithDate(expectedString, deltaFromNow, culture, now, utcNow); } - static void VerifyWithDate(string expectedString, TimeSpan deltaFromBase, CultureInfo culture, DateTime baseDate, DateTime baseDateUtc) + static void VerifyWithDate(string expectedString, TimeSpan deltaFromBase, CultureInfo? culture, DateTime baseDate, DateTime baseDateUtc) { Assert.Equal(expectedString, baseDateUtc.Add(deltaFromBase).Humanize(utcDate: true, dateToCompareAgainst: baseDateUtc, culture: culture)); Assert.Equal(expectedString, baseDate.Add(deltaFromBase).Humanize(false, baseDate, culture: culture)); @@ -31,7 +31,7 @@ static void VerifyWithDate(string expectedString, TimeSpan deltaFromBase, Cultur Assert.Equal(expectedString, baseDate.Add(deltaFromBase).Humanize(null, baseDate, culture: culture)); } - public static void Verify(string expectedString, int unit, TimeUnit timeUnit, Tense tense, double? precision = null, CultureInfo culture = null, DateTime? baseDate = null, DateTime? baseDateUtc = null) + public static void Verify(string expectedString, int unit, TimeUnit timeUnit, Tense tense, double? precision = null, CultureInfo? culture = null, DateTime? baseDate = null, DateTime? baseDateUtc = null) { // We lock this as these tests can be multi-threaded and we're setting a static lock (LockObject) @@ -85,7 +85,7 @@ public static void Verify(string expectedString, int unit, TimeUnit timeUnit, Te } else { - VerifyWithDate(expectedString, deltaFromNow, culture, baseDate.Value, baseDateUtc.Value); + VerifyWithDate(expectedString, deltaFromNow, culture, baseDate.Value, baseDateUtc!.Value); } } } diff --git a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs index 372798986..3f10221fc 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs @@ -44,7 +44,7 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim [Theory] [InlineData(19854651984, 1, TimeUnit.Second, null, "18,49 GB/s")] [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18,49 GB/s")] - public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue) + public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string? format, string expectedValue) { var size = ByteSize.FromBytes(bytes); var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds); diff --git a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs index 47db0a373..27dab2544 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs @@ -7,7 +7,7 @@ public class ByteSizeExtensionsTests [InlineData(2, null, "2 TB")] [InlineData(2, "GB", "2048 GB")] [InlineData(2.123, "#.#", "2,1 TB")] - public void HumanizesTerabytes(double input, string format, string expectedValue) => + public void HumanizesTerabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); [Theory] @@ -16,7 +16,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue [InlineData(2, null, "2 GB")] [InlineData(2, "MB", "2048 MB")] [InlineData(2.123, "#.##", "2,12 GB")] - public void HumanizesGigabytes(double input, string format, string expectedValue) => + public void HumanizesGigabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); [Theory] @@ -25,7 +25,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(2, null, "2 MB")] [InlineData(2, "KB", "2048 kB")] [InlineData(2.123, "#", "2 MB")] - public void HumanizesMegabytes(double input, string format, string expectedValue) => + public void HumanizesMegabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); [Theory] @@ -34,7 +34,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue [InlineData(2, null, "2 kB")] [InlineData(2, "B", "2048 B")] [InlineData(2.123, "#.####", "2,123 kB")] - public void HumanizesKilobytes(double input, string format, string expectedValue) => + public void HumanizesKilobytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); [Theory] @@ -48,7 +48,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(10000000, "KB", "9765,63 kB")] [InlineData(10000000, "#,##0 KB", "9.766 kB")] [InlineData(10000000, "#,##0.# KB", "9.765,6 kB")] - public void HumanizesBytes(double input, string format, string expectedValue) => + public void HumanizesBytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Bytes().Humanize(format)); [Theory] @@ -57,7 +57,7 @@ public void HumanizesBytes(double input, string format, string expectedValue) => [InlineData(2, null, "2 bit")] [InlineData(12, "B", "1,5 B")] [InlineData(10000, "#.# KB", "1,2 kB")] - public void HumanizesBits(long input, string format, string expectedValue) => + public void HumanizesBits(long input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } } diff --git a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs index 20f9b4e32..63b21db1b 100644 --- a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs @@ -7,7 +7,7 @@ public class ByteSizeExtensionsTests [InlineData(2, null, "2 To")] [InlineData(2, "GB", "2048 Go")] [InlineData(2.123, "#.#", "2,1 To")] - public void HumanizesTerabytes(double input, string format, string expectedValue) => + public void HumanizesTerabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); [Theory] @@ -16,7 +16,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue [InlineData(2, null, "2 Go")] [InlineData(2, "MB", "2048 Mo")] [InlineData(2.123, "#.##", "2,12 Go")] - public void HumanizesGigabytes(double input, string format, string expectedValue) => + public void HumanizesGigabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); [Theory] @@ -25,7 +25,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(2, null, "2 Mo")] [InlineData(2, "KB", "2048 Ko")] [InlineData(2.123, "#", "2 Mo")] - public void HumanizesMegabytes(double input, string format, string expectedValue) => + public void HumanizesMegabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); [Theory] @@ -34,7 +34,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue [InlineData(2, null, "2 Ko")] [InlineData(2, "B", "2048 o")] [InlineData(2.123, "#.####", "2,123 Ko")] - public void HumanizesKilobytes(double input, string format, string expectedValue) => + public void HumanizesKilobytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); [Theory] @@ -48,7 +48,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(10000000, "KB", "9765,63 Ko")] [InlineData(10000000, "#,##0 KB", "9 766 Ko")] [InlineData(10000000, "#,##0.# KB", "9 765,6 Ko")] - public void HumanizesBytes(double input, string format, string expectedValue) + public void HumanizesBytes(double input, string? format, string expectedValue) { expectedValue = expectedValue.Replace(" ", NumberFormatInfo.CurrentInfo.NumberGroupSeparator); Assert.Equal( @@ -64,7 +64,7 @@ public void HumanizesBytes(double input, string format, string expectedValue) [InlineData(2, null, "2 b")] [InlineData(12, "B", "1,5 o")] [InlineData(10000, "#.# KB", "1,2 Ko")] - public void HumanizesBits(long input, string format, string expectedValue) => + public void HumanizesBits(long input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } } diff --git a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs index 753bedac7..4e265d988 100644 --- a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs @@ -7,7 +7,7 @@ public class ByteSizeExtensionsTests [InlineData(2, null, "2 TB")] [InlineData(2, "GB", "2048 GB")] [InlineData(2.123, "#.#", "2,1 TB")] - public void HumanizesTerabytes(double input, string format, string expectedValue) => + public void HumanizesTerabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); [Theory] @@ -16,7 +16,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue [InlineData(2, null, "2 GB")] [InlineData(2, "MB", "2048 MB")] [InlineData(2.123, "#.##", "2,12 GB")] - public void HumanizesGigabytes(double input, string format, string expectedValue) => + public void HumanizesGigabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); [Theory] @@ -25,7 +25,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(2, null, "2 MB")] [InlineData(2, "KB", "2048 kB")] [InlineData(2.123, "#", "2 MB")] - public void HumanizesMegabytes(double input, string format, string expectedValue) => + public void HumanizesMegabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); [Theory] @@ -34,7 +34,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue [InlineData(2, null, "2 kB")] [InlineData(2, "B", "2048 B")] [InlineData(2.123, "#.####", "2,123 kB")] - public void HumanizesKilobytes(double input, string format, string expectedValue) => + public void HumanizesKilobytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); [Theory] @@ -48,7 +48,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(10000000, "KB", "9765,63 kB")] [InlineData(10000000, "#,##0 KB", "9.766 kB")] [InlineData(10000000, "#,##0.# KB", "9.765,6 kB")] - public void HumanizesBytes(double input, string format, string expectedValue) => + public void HumanizesBytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Bytes().Humanize(format)); [Theory] @@ -57,7 +57,7 @@ public void HumanizesBytes(double input, string format, string expectedValue) => [InlineData(2, null, "2 b")] [InlineData(12, "B", "1,5 B")] [InlineData(10000, "#.# KB", "1,2 kB")] - public void HumanizesBits(long input, string format, string expectedValue) => + public void HumanizesBits(long input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } } diff --git a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs index 01b608958..d49320ce6 100644 --- a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs @@ -44,7 +44,7 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim [Theory] [InlineData(19854651984, 1, TimeUnit.Second, null, "18,49 GB/s")] [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18,49 GB/s")] - public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue) + public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string? format, string expectedValue) { var size = ByteSize.FromBytes(bytes); var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds); diff --git a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs index 79e637abd..c95c3161c 100644 --- a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs @@ -7,7 +7,7 @@ public class ByteSizeExtensionsTests [InlineData(2, null, "2 TB")] [InlineData(2, "GB", "2048 GB")] [InlineData(2.123, "#.#", "2,1 TB")] - public void HumanizesTerabytes(double input, string format, string expectedValue) => + public void HumanizesTerabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); [Theory] @@ -16,7 +16,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue [InlineData(2, null, "2 GB")] [InlineData(2, "MB", "2048 MB")] [InlineData(2.123, "#.##", "2,12 GB")] - public void HumanizesGigabytes(double input, string format, string expectedValue) => + public void HumanizesGigabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); [Theory] @@ -25,7 +25,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(2, null, "2 MB")] [InlineData(2, "KB", "2048 KB")] [InlineData(2.123, "#", "2 MB")] - public void HumanizesMegabytes(double input, string format, string expectedValue) => + public void HumanizesMegabytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); [Theory] @@ -34,7 +34,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue [InlineData(2, null, "2 KB")] [InlineData(2, "B", "2048 B")] [InlineData(2.123, "#.####", "2,123 KB")] - public void HumanizesKilobytes(double input, string format, string expectedValue) => + public void HumanizesKilobytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); #if NET6_0_OR_GREATER // the lb/lb-LU locales apparently don't have the correct group separator pre .NET 6 @@ -49,7 +49,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(10000000, "KB", "9765,63 KB")] [InlineData(10000000, "#,##0 KB", "9.766 KB")] [InlineData(10000000, "#,##0.# KB", "9.765,6 KB")] - public void HumanizesBytes(double input, string format, string expectedValue) => + public void HumanizesBytes(double input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Bytes().Humanize(format)); #endif @@ -59,6 +59,6 @@ public void HumanizesBytes(double input, string format, string expectedValue) => [InlineData(2, null, "2 bit")] [InlineData(12, "B", "1,5 B")] [InlineData(10000, "#.# KB", "1,2 KB")] - public void HumanizesBits(long input, string format, string expectedValue) => + public void HumanizesBits(long input, string? format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } diff --git a/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs index 4aeaa782f..37bdfd443 100644 --- a/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs @@ -443,7 +443,7 @@ public void NoTimeToWords() [InlineData(6 * 24 * 60 * 60 * 1000, 1, "ru-RU", "6 дней", ", ")] [InlineData(11 * 60 * 60 * 1000, 1, "ar", "11 ساعة", ", ")] [InlineData(3603001, 2, "it-IT", "1 ora e 3 secondi", null)] - public void CanSpecifyCultureExplicitly(int ms, int precision, string culture, string expected, string collectionSeparator) + public void CanSpecifyCultureExplicitly(int ms, int precision, string culture, string expected, string? collectionSeparator) { var actual = TimeSpan.FromMilliseconds(ms).Humanize(precision: precision, culture: new(culture), collectionSeparator: collectionSeparator); Assert.Equal(expected, actual); diff --git a/src/Humanizer.Tests.Shared/ToQuantityTests.cs b/src/Humanizer.Tests.Shared/ToQuantityTests.cs index 2f234a481..b0e3ba217 100644 --- a/src/Humanizer.Tests.Shared/ToQuantityTests.cs +++ b/src/Humanizer.Tests.Shared/ToQuantityTests.cs @@ -88,7 +88,7 @@ public void ToQuantityWords(string word, int quantity, string expected) => [InlineData("dollar", 1, "C0", "$1 dollar")] [InlineData("dollar", 2, "C0", "$2 dollars")] [InlineData("dollar", 2, "C2", "$2.00 dollars")] - public void ToQuantityWordsWithCurrentCultureFormatting(string word, int quantity, string format, string expected) => + public void ToQuantityWordsWithCurrentCultureFormatting(string word, int quantity, string? format, string expected) => Assert.Equal(expected, word.ToQuantity(quantity, format)); [Theory] diff --git a/src/Humanizer.Tests.Shared/TruncatorTests.cs b/src/Humanizer.Tests.Shared/TruncatorTests.cs index a02fe4621..8d65af2ed 100644 --- a/src/Humanizer.Tests.Shared/TruncatorTests.cs +++ b/src/Humanizer.Tests.Shared/TruncatorTests.cs @@ -9,7 +9,7 @@ public class TruncatorTests [InlineData("Text longer than truncate length", 10, "Text long…")] [InlineData("Text with length equal to truncate length", 41, "Text with length equal to truncate length")] [InlineData("Text smaller than truncate length", 34, "Text smaller than truncate length")] - public void Truncate(string input, int length, string expectedOutput) => + public void Truncate(string? input, int length, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length)); [Theory] @@ -19,7 +19,7 @@ public void Truncate(string input, int length, string expectedOutput) => [InlineData("Text longer than truncate length", 10, "Text long…")] [InlineData("Text with length equal to truncate length", 41, "Text with length equal to truncate length")] [InlineData("Text smaller than truncate length", 34, "Text smaller than truncate length")] - public void TruncateWithFixedLengthTruncator(string input, int length, string expectedOutput) => + public void TruncateWithFixedLengthTruncator(string? input, int length, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, Truncator.FixedLength)); [Theory] @@ -29,7 +29,7 @@ public void TruncateWithFixedLengthTruncator(string input, int length, string ex [InlineData("Text with more characters than truncate length", 10, "Text with m…")] [InlineData("Text with number of characters equal to truncate length", 47, "Text with number of characters equal to truncate length")] [InlineData("Text with less characters than truncate length", 41, "Text with less characters than truncate length")] - public void TruncateWithFixedNumberOfCharactersTruncator(string input, int length, string expectedOutput) => + public void TruncateWithFixedNumberOfCharactersTruncator(string? input, int length, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, Truncator.FixedNumberOfCharacters)); [Theory] @@ -40,7 +40,7 @@ public void TruncateWithFixedNumberOfCharactersTruncator(string input, int lengt [InlineData("Text with number of words equal to truncate length", 9, "Text with number of words equal to truncate length")] [InlineData("Text with less words than truncate length", 8, "Text with less words than truncate length")] [InlineData("Words are\nsplit\rby\twhitespace", 4, "Words are\nsplit\rby…")] - public void TruncateWithFixedNumberOfWordsTruncator(string input, int length, string expectedOutput) => + public void TruncateWithFixedNumberOfWordsTruncator(string? input, int length, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, Truncator.FixedNumberOfWords)); [Theory] @@ -52,7 +52,7 @@ public void TruncateWithFixedNumberOfWordsTruncator(string input, int length, st [InlineData("Text smaller than truncate length", 34, "...", "Text smaller than truncate length")] [InlineData("Text with delimiter length greater than truncate length truncates to fixed length without truncation string", 2, "...", "Te")] [InlineData("Null truncation string truncates to truncate length without truncation string", 4, null, "Null")] - public void TruncateWithTruncationString(string input, int length, string truncationString, string expectedOutput) => + public void TruncateWithTruncationString(string? input, int length, string? truncationString, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, truncationString)); [Theory] @@ -65,7 +65,7 @@ public void TruncateWithTruncationString(string input, int length, string trunca [InlineData("Text smaller than truncate length", 34, "...", "Text smaller than truncate length")] [InlineData("Text with delimiter length greater than truncate length truncates to fixed length without truncation string", 2, "...", "Te")] [InlineData("Null truncation string truncates to truncate length without truncation string", 4, null, "Null")] - public void TruncateWithTruncationStringAndFixedLengthTruncator(string input, int length, string truncationString, string expectedOutput) => + public void TruncateWithTruncationStringAndFixedLengthTruncator(string? input, int length, string? truncationString, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, truncationString, Truncator.FixedLength)); [Theory] @@ -79,7 +79,7 @@ public void TruncateWithTruncationStringAndFixedLengthTruncator(string input, in [InlineData("Text with delimiter length greater than truncate length truncates to fixed length without truncation string", 2, "...", "Te")] [InlineData("Text with additional spaces and null truncate string", 10, null, "Text with ad")] [InlineData("Text with additional spaces and empty string as truncate string", 10, "", "Text with ad")] - public void TruncateWithTruncationStringAndFixedNumberOfCharactersTruncator(string input, int length, string truncationString, string expectedOutput) => + public void TruncateWithTruncationStringAndFixedNumberOfCharactersTruncator(string? input, int length, string? truncationString, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, truncationString, Truncator.FixedNumberOfCharacters)); [Theory] @@ -92,7 +92,7 @@ public void TruncateWithTruncationStringAndFixedNumberOfCharactersTruncator(stri [InlineData("Text with less words than truncate length", 8, "...", "Text with less words than truncate length")] [InlineData("Words are\nsplit\rby\twhitespace", 4, "...", "Words are\nsplit\rby...")] [InlineData("Null truncation string truncates to truncate length without truncation string", 4, null, "Null truncation string truncates")] - public void TruncateWithTruncationStringAndFixedNumberOfWordsTruncator(string input, int length, string truncationString, string expectedOutput) => + public void TruncateWithTruncationStringAndFixedNumberOfWordsTruncator(string? input, int length, string? truncationString, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, truncationString, Truncator.FixedNumberOfWords)); [Theory] @@ -102,7 +102,7 @@ public void TruncateWithTruncationStringAndFixedNumberOfWordsTruncator(string in [InlineData("Text longer than truncate length", 10, "…te length")] [InlineData("Text with length equal to truncate length", 41, "Text with length equal to truncate length")] [InlineData("Text smaller than truncate length", 34, "Text smaller than truncate length")] - public void TruncateWithFixedLengthTruncatorTruncateFromLeft(string input, int length, string expectedOutput) => + public void TruncateWithFixedLengthTruncatorTruncateFromLeft(string? input, int length, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, Truncator.FixedLength, TruncateFrom.Left)); [Theory] @@ -113,7 +113,7 @@ public void TruncateWithFixedLengthTruncatorTruncateFromLeft(string input, int l [InlineData("Text with number of characters equal to truncate length", 47, "Text with number of characters equal to truncate length")] [InlineData("Text with less characters than truncate length", 41, "Text with less characters than truncate length")] [InlineData("Text with strange characters ^$(*^ and more ^$**)% ", 10, "…rs ^$(*^ and more ^$**)% ")] - public void TruncateWithFixedNumberOfCharactersTruncatorTruncateFromLeft(string input, int length, string expectedOutput) => + public void TruncateWithFixedNumberOfCharactersTruncatorTruncateFromLeft(string? input, int length, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, Truncator.FixedNumberOfCharacters, TruncateFrom.Left)); [Theory] @@ -125,7 +125,7 @@ public void TruncateWithFixedNumberOfCharactersTruncatorTruncateFromLeft(string [InlineData("Text with less words than truncate length", 8, "Text with less words than truncate length")] [InlineData("Words are\nsplit\rby\twhitespace", 4, "…are\nsplit\rby\twhitespace")] [InlineData("Text with whitespace at the end ", 4, "…whitespace at the end")] - public void TruncateWithFixedNumberOfWordsTruncatorTruncateFromLeft(string input, int length, string expectedOutput) => + public void TruncateWithFixedNumberOfWordsTruncatorTruncateFromLeft(string? input, int length, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, Truncator.FixedNumberOfWords, TruncateFrom.Left)); [Theory] @@ -138,7 +138,7 @@ public void TruncateWithFixedNumberOfWordsTruncatorTruncateFromLeft(string input [InlineData("Text smaller than truncate length", 34, "...", "Text smaller than truncate length")] [InlineData("Text with delimiter length greater than truncate length truncates to fixed length without truncation string", 2, "...", "ng")] [InlineData("Null truncation string truncates to truncate length without truncation string", 4, null, "ring")] - public void TruncateWithTruncationStringAndFixedLengthTruncatorTruncateFromLeft(string input, int length, string truncationString, string expectedOutput) => + public void TruncateWithTruncationStringAndFixedLengthTruncatorTruncateFromLeft(string? input, int length, string? truncationString, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, truncationString, Truncator.FixedLength, TruncateFrom.Left)); [Theory] @@ -151,7 +151,7 @@ public void TruncateWithTruncationStringAndFixedLengthTruncatorTruncateFromLeft( [InlineData("Text with less characters than truncate length", 41, "...", "Text with less characters than truncate length")] [InlineData("Text with delimiter length greater than truncate length truncates to fixed number of characters without truncation string", 2, "...", "ng")] [InlineData("Null truncation string truncates to truncate length without truncation string", 4, null, "ring")] - public void TruncateWithTruncationStringAndFixedNumberOfCharactersTruncatorTruncateFromLeft(string input, int length, string truncationString, string expectedOutput) => + public void TruncateWithTruncationStringAndFixedNumberOfCharactersTruncatorTruncateFromLeft(string? input, int length, string? truncationString, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, truncationString, Truncator.FixedNumberOfCharacters, TruncateFrom.Left)); [Theory] @@ -165,7 +165,7 @@ public void TruncateWithTruncationStringAndFixedNumberOfCharactersTruncatorTrunc [InlineData("Words are\nsplit\rby\twhitespace", 4, "...", "...are\nsplit\rby\twhitespace")] [InlineData("Null truncation string truncates to truncate length without truncation string", 4, null, "length without truncation string")] [InlineData("Text with whitespace at the end ", 4, "...", "...whitespace at the end")] - public void TruncateWithTruncationStringAndFixedNumberOfWordsTruncatorTruncateFromLeft(string input, int length, string truncationString, string expectedOutput) => + public void TruncateWithTruncationStringAndFixedNumberOfWordsTruncatorTruncateFromLeft(string? input, int length, string? truncationString, string? expectedOutput) => Assert.Equal(expectedOutput, input.Truncate(length, truncationString, Truncator.FixedNumberOfWords, TruncateFrom.Left)); } } diff --git a/src/Humanizer.Tests.Shared/UseCultureAttribute.cs b/src/Humanizer.Tests.Shared/UseCultureAttribute.cs index 03ad6095b..f91edf210 100644 --- a/src/Humanizer.Tests.Shared/UseCultureAttribute.cs +++ b/src/Humanizer.Tests.Shared/UseCultureAttribute.cs @@ -12,8 +12,8 @@ namespace Humanizer.Tests; public class UseCultureAttribute : BeforeAfterTestAttribute { readonly Lazy culture; - CultureInfo originalCulture; - CultureInfo originalUICulture; + CultureInfo? originalCulture; + CultureInfo? originalUICulture; /// /// Replaces the culture and UI culture of the current thread with @@ -53,7 +53,7 @@ public override void Before(MethodInfo methodUnderTest) /// The method under test public override void After(MethodInfo methodUnderTest) { - CultureInfo.CurrentCulture = originalCulture; - CultureInfo.CurrentUICulture = originalUICulture; + CultureInfo.CurrentCulture = originalCulture!; + CultureInfo.CurrentUICulture = originalUICulture!; } } \ No newline at end of file diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 14d77e9ff..1d5031b94 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -1,6 +1,7 @@  net8.0;net48 + enable From 6130a4574aae782533e4c91f2b61ee88c069e4a5 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 20:42:01 +1100 Subject: [PATCH 04/39] . --- .../DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs | 4 +++- .../DefaultDateOnlyHumanizeStrategy.cs | 3 ++- .../DefaultDateTimeHumanizeStrategy.cs | 1 + .../DefaultDateTimeOffsetHumanizeStrategy.cs | 1 + .../DefaultTimeOnlyHumanizeStrategy.cs | 3 ++- .../DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs | 3 ++- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs index 959db0c01..9451ade8b 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs @@ -1,4 +1,6 @@ -namespace Humanizer +#nullable enable + +namespace Humanizer { /// /// Algorithms used to convert distance between two dates into words. diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs index e868c3519..87581ad4c 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs @@ -1,4 +1,5 @@ -#if NET6_0_OR_GREATER +#nullable enable +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs index 46fa830ff..30ce7f030 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs @@ -1,3 +1,4 @@ +#nullable enable namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs index 16ef0861e..61007acd8 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs @@ -1,3 +1,4 @@ +#nullable enable namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs index 85f839961..c910f266f 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs @@ -1,4 +1,5 @@ -#if NET6_0_OR_GREATER +#nullable enable +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs index ce9c3d841..dc21c300e 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs @@ -1,4 +1,5 @@ -#if NET6_0_OR_GREATER +#nullable enable +#if NET6_0_OR_GREATER namespace Humanizer { From c32ecae26c1ace3a34ab1e37b28fb8dd4fa95c85 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 20:46:23 +1100 Subject: [PATCH 05/39] . --- .../DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs | 4 +++- .../IDateTimeOffsetHumanizeStrategy.cs | 4 +++- .../DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs | 4 +++- .../PrecisionDateOnlyHumanizeStrategy.cs | 4 +++- .../PrecisionDateTimeHumanizeStrategy.cs | 2 ++ .../PrecisionDateTimeOffsetHumanizeStrategy.cs | 2 ++ .../PrecisionTimeOnlyHumanizeStrategy.cs | 4 +++- 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs index 272236759..df8ac7232 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs @@ -1,4 +1,6 @@ -namespace Humanizer +#nullable enable + +namespace Humanizer { /// /// Implement this interface to create a new strategy for DateTime.Humanize and hook it in the Configurator.DateTimeHumanizeStrategy diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs index 28eae6aef..b3bc49657 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs @@ -1,4 +1,6 @@ -namespace Humanizer +#nullable enable + +namespace Humanizer { /// /// Implement this interface to create a new strategy for DateTime.Humanize and hook it in the Configurator.DateTimeOffsetHumanizeStrategy diff --git a/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs index 01659062a..0baaecdfc 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs @@ -1,4 +1,6 @@ -#if NET6_0_OR_GREATER +#nullable enable + +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs index 75792576e..5e5270e19 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs @@ -1,4 +1,6 @@ -#if NET6_0_OR_GREATER +#nullable enable + +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs index d35209583..f7af52f30 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs index 8df72d2f8..dc1f63340 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs index 4b86f4001..f18601c85 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs @@ -1,4 +1,6 @@ -#if NET6_0_OR_GREATER +#nullable enable + +#if NET6_0_OR_GREATER namespace Humanizer { From 966d0ef60dabf1f0fab715c8fd80a7674f42821e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 20:48:12 +1100 Subject: [PATCH 06/39] . --- src/Humanizer/Configuration/CollectionFormatterRegistry.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Humanizer/Configuration/CollectionFormatterRegistry.cs b/src/Humanizer/Configuration/CollectionFormatterRegistry.cs index f1b66209b..1d834ad8a 100644 --- a/src/Humanizer/Configuration/CollectionFormatterRegistry.cs +++ b/src/Humanizer/Configuration/CollectionFormatterRegistry.cs @@ -1,4 +1,6 @@ -namespace Humanizer +#nullable enable + +namespace Humanizer { class CollectionFormatterRegistry : LocaliserRegistry { From a7d9740d833a59c565dc5847bc70b2bdee89c142 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 21:31:41 +1100 Subject: [PATCH 07/39] . --- src/Humanizer/FluentDate/PrepositionsExtensions.cs | 3 ++- src/Humanizer/Inflections/Vocabularies.cs | 3 ++- src/Humanizer/Inflections/Vocabulary.cs | 11 ++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Humanizer/FluentDate/PrepositionsExtensions.cs b/src/Humanizer/FluentDate/PrepositionsExtensions.cs index 85b94a4c4..30e9a40aa 100644 --- a/src/Humanizer/FluentDate/PrepositionsExtensions.cs +++ b/src/Humanizer/FluentDate/PrepositionsExtensions.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// extensions related to spatial or temporal relations diff --git a/src/Humanizer/Inflections/Vocabularies.cs b/src/Humanizer/Inflections/Vocabularies.cs index 143eb4fb7..323ee5717 100644 --- a/src/Humanizer/Inflections/Vocabularies.cs +++ b/src/Humanizer/Inflections/Vocabularies.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Container for registered Vocabularies. At present, only a single vocabulary is supported: Default. diff --git a/src/Humanizer/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs index d80d7e6de..caf0f778c 100644 --- a/src/Humanizer/Inflections/Vocabulary.cs +++ b/src/Humanizer/Inflections/Vocabulary.cs @@ -1,4 +1,5 @@ -namespace Humanizer; +#nullable enable +namespace Humanizer; /// /// A container for exceptions to simple pluralization/singularization rules. @@ -66,7 +67,7 @@ public void AddSingular(string rule, string replacement) => /// /// Word to be pluralized /// Normally you call Pluralize on singular words; but if you're unsure call it with false - public string Pluralize(string word, bool inputIsKnownToBeSingular = true) + public string? Pluralize(string word, bool inputIsKnownToBeSingular = true) { var s = LetterS(word); if (s != null) @@ -134,7 +135,7 @@ public string Singularize(string word, bool inputIsKnownToBePlural = true, bool return word; } - string ApplyRules(IList rules, string word, bool skipFirstRule) + string? ApplyRules(IList rules, string? word, bool skipFirstRule) { if (word == null) { @@ -179,7 +180,7 @@ static string MatchUpperCase(string word, string replacement) => /// /// If the word is the letter s, singular or plural, return the letter s singular /// - string LetterS(string word) + string? LetterS(string word) { var s = letterS.Match(word); return s.Groups.Count > 1 ? s.Groups[1].Value : null; @@ -189,7 +190,7 @@ class Rule(string pattern, string replacement) { readonly Regex regex = new(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); - public string Apply(string word) + public string? Apply(string word) { if (!regex.IsMatch(word)) { From 8569ce2f89f6a5dab07cf672a1097aa0a139c4dc Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 21:35:32 +1100 Subject: [PATCH 08/39] . --- .../NumberToWords/SerbianCyrlNumberToWordsConverter.cs | 3 ++- .../Localisation/Ordinalizers/ArmenianOrdinalizer.cs | 3 ++- .../Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs | 3 ++- .../Localisation/Ordinalizers/DefaultOrdinalizer.cs | 4 +++- .../Localisation/Ordinalizers/FrenchOrdinalizer.cs | 3 ++- src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs | 3 ++- .../Localisation/Ordinalizers/RomanianOrdinalizer.cs | 4 +++- .../Localisation/Ordinalizers/SpanishOrdinalizer.cs | 3 ++- .../Localisation/Ordinalizers/UkrainianOrdinalizer.cs | 3 ++- .../Localisation/ResourceKeys.TimeSpanHumanize.cs | 3 ++- src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs | 3 ++- src/Humanizer/Localisation/Resources.cs | 8 +++++--- src/Humanizer/Localisation/Tense.cs | 3 ++- src/Humanizer/Localisation/TimeUnit.cs | 3 ++- src/Humanizer/Transformer/ICulturedStringTransformer.cs | 3 ++- src/Humanizer/Transformer/IStringTransformer.cs | 2 ++ src/Humanizer/Transformer/ToLowerCase.cs | 3 ++- src/Humanizer/Transformer/ToSentenceCase.cs | 5 +++-- src/Humanizer/Transformer/ToTitleCase.cs | 5 +++-- src/Humanizer/Transformer/ToUpperCase.cs | 5 +++-- 20 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs index 196cada14..bda1ff628 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class SerbianCyrlNumberToWordsConverter(CultureInfo culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs index 279389f72..090c17a9c 100644 --- a/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class ArmenianOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs index 49a7aa323..6f8c926f0 100644 --- a/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class AzerbaijaniOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs index 348a37d70..d7b4ff52a 100644 --- a/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs @@ -1,4 +1,6 @@ -namespace Humanizer + +#nullable enable +namespace Humanizer { class DefaultOrdinalizer : IOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs index 295b5fa5e..9f6ebdbfe 100644 --- a/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class FrenchOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs index 2d7148cac..0ba117bd7 100644 --- a/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// The interface used to localise the Ordinalize method diff --git a/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs index fe2f8c01c..dbb30ba90 100644 --- a/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs @@ -1,4 +1,6 @@ -namespace Humanizer + +#nullable enable +namespace Humanizer { class RomanianOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs index 48fba9c3f..b091ce23c 100644 --- a/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class SpanishOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs index cd01189bc..ca9f19d34 100644 --- a/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class UkrainianOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs b/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs index 648591a9a..0582893d4 100644 --- a/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs +++ b/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs @@ -1,4 +1,5 @@ -namespace Humanizer; +#nullable enable +namespace Humanizer; public partial class ResourceKeys { diff --git a/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs b/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs index f7aa2a3f6..3385bbefc 100644 --- a/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs +++ b/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs @@ -1,4 +1,5 @@ -namespace Humanizer; +#nullable enable +namespace Humanizer; public partial class ResourceKeys { diff --git a/src/Humanizer/Localisation/Resources.cs b/src/Humanizer/Localisation/Resources.cs index f2a11eb27..2af69c3e2 100644 --- a/src/Humanizer/Localisation/Resources.cs +++ b/src/Humanizer/Localisation/Resources.cs @@ -1,4 +1,6 @@ -using System.Resources; +#nullable enable +using System.Diagnostics.CodeAnalysis; +using System.Resources; namespace Humanizer { @@ -15,7 +17,7 @@ public static class Resources /// The name of the resource to retrieve. /// The culture of the resource to retrieve. If not specified, current thread's UI culture is used. /// The value of the resource localized for the specified culture. - public static string GetResource(string resourceKey, CultureInfo culture = null) => + public static string? GetResource(string resourceKey, CultureInfo? culture = null) => ResourceManager.GetString(resourceKey, culture); /// @@ -25,7 +27,7 @@ public static string GetResource(string resourceKey, CultureInfo culture = null) /// The culture of the resource to retrieve. If not specified, current thread's UI culture is used. /// The value of the resource localized for the specified culture if found; null otherwise. /// true if the specified string resource was found for the given culture; otherwise, false. - public static bool TryGetResource(string resourceKey, CultureInfo culture, out string result) + public static bool TryGetResource(string resourceKey, CultureInfo? culture, [NotNullWhen(true)] out string? result) { culture ??= CultureInfo.CurrentUICulture; var resourceSet = ResourceManager.GetResourceSet(culture, createIfNotExists: false, tryParents: false); diff --git a/src/Humanizer/Localisation/Tense.cs b/src/Humanizer/Localisation/Tense.cs index e81c9e14c..5bcecf015 100644 --- a/src/Humanizer/Localisation/Tense.cs +++ b/src/Humanizer/Localisation/Tense.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Enumerates the possible time references; past or future. diff --git a/src/Humanizer/Localisation/TimeUnit.cs b/src/Humanizer/Localisation/TimeUnit.cs index bede6631f..0a6d90daf 100644 --- a/src/Humanizer/Localisation/TimeUnit.cs +++ b/src/Humanizer/Localisation/TimeUnit.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { public enum TimeUnit { diff --git a/src/Humanizer/Transformer/ICulturedStringTransformer.cs b/src/Humanizer/Transformer/ICulturedStringTransformer.cs index acfeba711..538283947 100644 --- a/src/Humanizer/Transformer/ICulturedStringTransformer.cs +++ b/src/Humanizer/Transformer/ICulturedStringTransformer.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Can transform a string with the given culture diff --git a/src/Humanizer/Transformer/IStringTransformer.cs b/src/Humanizer/Transformer/IStringTransformer.cs index cbb893463..b97b73106 100644 --- a/src/Humanizer/Transformer/IStringTransformer.cs +++ b/src/Humanizer/Transformer/IStringTransformer.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace Humanizer { /// diff --git a/src/Humanizer/Transformer/ToLowerCase.cs b/src/Humanizer/Transformer/ToLowerCase.cs index 9f6f38a23..90899375a 100644 --- a/src/Humanizer/Transformer/ToLowerCase.cs +++ b/src/Humanizer/Transformer/ToLowerCase.cs @@ -1,3 +1,4 @@ +#nullable enable namespace Humanizer { class ToLowerCase : ICulturedStringTransformer @@ -5,7 +6,7 @@ class ToLowerCase : ICulturedStringTransformer public string Transform(string input) => Transform(input, null); - public string Transform(string input, CultureInfo culture) + public string Transform(string input, CultureInfo? culture) { culture ??= CultureInfo.CurrentCulture; diff --git a/src/Humanizer/Transformer/ToSentenceCase.cs b/src/Humanizer/Transformer/ToSentenceCase.cs index 484ab9b37..923a8e918 100644 --- a/src/Humanizer/Transformer/ToSentenceCase.cs +++ b/src/Humanizer/Transformer/ToSentenceCase.cs @@ -1,11 +1,12 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class ToSentenceCase : ICulturedStringTransformer { public string Transform(string input) => Transform(input, null); - public string Transform(string input, CultureInfo culture) + public string Transform(string input, CultureInfo? culture) { culture ??= CultureInfo.CurrentCulture; diff --git a/src/Humanizer/Transformer/ToTitleCase.cs b/src/Humanizer/Transformer/ToTitleCase.cs index ed0cea153..fc6fdc529 100644 --- a/src/Humanizer/Transformer/ToTitleCase.cs +++ b/src/Humanizer/Transformer/ToTitleCase.cs @@ -1,11 +1,12 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class ToTitleCase : ICulturedStringTransformer { public string Transform(string input) => Transform(input, null); - public string Transform(string input, CultureInfo culture) + public string Transform(string input, CultureInfo? culture) { culture ??= CultureInfo.CurrentCulture; diff --git a/src/Humanizer/Transformer/ToUpperCase.cs b/src/Humanizer/Transformer/ToUpperCase.cs index 2296da26e..7c9276112 100644 --- a/src/Humanizer/Transformer/ToUpperCase.cs +++ b/src/Humanizer/Transformer/ToUpperCase.cs @@ -1,11 +1,12 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class ToUpperCase : ICulturedStringTransformer { public string Transform(string input) => Transform(input, null); - public string Transform(string input, CultureInfo culture) + public string Transform(string input, CultureInfo? culture) { culture ??= CultureInfo.CurrentCulture; From a06be6caef66583e8e080b5f9c6a4beaa6a274f2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 21:42:27 +1100 Subject: [PATCH 09/39] . --- .../NumberToWords/LithuanianNumberToWordsConverter.cs | 3 ++- .../NumberToWords/LuxembourgishNumberToWordsConverter.cs | 3 ++- .../NumberToWords/MalteseNumberToWordsConvertor.cs | 3 ++- .../NumberToWords/PolishNumberToWordsConverter.cs | 3 ++- .../NumberToWords/PortugueseNumberToWordsConverter.cs | 3 ++- .../NumberToWords/RomanianNumberToWordsConverter.cs | 3 ++- .../NumberToWords/RussianNumberToWordsConverter.cs | 3 ++- .../NumberToWords/SerbianNumberToWordsConverter.cs | 3 ++- .../NumberToWords/SlovenianNumberToWordsConverter.cs | 3 ++- .../NumberToWords/SpanishNumberToWordsConverter.cs | 3 ++- .../NumberToWords/SwedishNumberToWordsConverter.cs | 9 +++++---- .../NumberToWords/TamilNumberToWordsConverter.cs | 7 +++++-- .../NumberToWords/TurkishNumberToWordConverter.cs | 3 ++- .../NumberToWords/UkrainianNumberToWordsConverter.cs | 3 ++- .../NumberToWords/UzbekCyrlNumberToWordConverter.cs | 3 ++- .../NumberToWords/UzbekLatnNumberToWordConverter.cs | 3 ++- .../NumberToWords/VietnameseNumberToWordsConverter.cs | 3 ++- 17 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs index acfb0304d..d8c1a9b84 100644 --- a/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class LithuanianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs index b929f8103..78d97776d 100644 --- a/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer; +#nullable enable +namespace Humanizer; class LuxembourgishNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs index ffe021da4..4afdfb296 100644 --- a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs +++ b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class MalteseNumberToWordsConvertor : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs index 7e3f2f34f..69bf80544 100644 --- a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class PolishNumberToWordsConverter(CultureInfo culture) : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs index 56382d1be..2f963dc33 100644 --- a/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class PortugueseNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs index b8ef26687..8c4770eb3 100644 --- a/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class RomanianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs index a9cbd1107..528e5427e 100644 --- a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class RussianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs index 71cf0be3f..a09c373c9 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class SerbianNumberToWordsConverter(CultureInfo culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs index 4e9ef1f24..7a5f5a672 100644 --- a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class SlovenianNumberToWordsConverter(CultureInfo culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs index c570f95f6..b9427e081 100644 --- a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class SpanishNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs index 2f66bd0f2..896d40b2e 100644 --- a/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class SwedishNumberToWordsConverter : GenderlessNumberToWordsConverter { @@ -8,9 +9,9 @@ class SwedishNumberToWordsConverter : GenderlessNumberToWordsConverter class Fact { public int Value { get; set; } - public string Name { get; set; } - public string Prefix { get; set; } - public string Postfix { get; set; } + public required string Name { get; set; } + public required string Prefix { get; set; } + public required string Postfix { get; set; } public bool DisplayOneUnit { get; set; } public GrammaticalGender Gender { get; set; } = GrammaticalGender.Neuter; } diff --git a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs index f2e9e6da9..874d9b04e 100644 --- a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs @@ -1,4 +1,7 @@ -namespace Humanizer +#nullable enable +using System.Diagnostics.CodeAnalysis; + +namespace Humanizer { class TamilNumberToWordsConverter : GenderlessNumberToWordsConverter { @@ -266,7 +269,7 @@ static string RemoveOnePrefix(string toWords) return toWords; } - static bool ExceptionNumbersToWords(long number, out string words) => + static bool ExceptionNumbersToWords(long number, [NotNullWhen(true)] out string? words) => OrdinalExceptions.TryGetValue(number, out words); } } diff --git a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs index 553913d3d..e64fbd52e 100644 --- a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class TurkishNumberToWordConverter : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs index c46056317..bdb17fa1b 100644 --- a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class UkrainianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs index 1a1a070cd..fe7322726 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class UzbekCyrlNumberToWordConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs index 6df6dbdcb..37d02765a 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class UzbekLatnNumberToWordConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs index 49861987c..a946cc04c 100644 --- a/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class VietnameseNumberToWordsConverter : GenderlessNumberToWordsConverter { From 776ae08625644174c84f17fbf563b59aa733e0d2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 21:53:44 +1100 Subject: [PATCH 10/39] . --- .../EnglishNumberToWordsConverter.cs | 8 ++- .../IcelandicNumberToWordsConverter.cs | 52 ++++++++++++------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs index c05be0c7d..fcffc050f 100644 --- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs @@ -1,4 +1,8 @@ -namespace Humanizer +#nullable enable + +using System.Diagnostics.CodeAnalysis; + +namespace Humanizer { class EnglishNumberToWordsConverter : GenderlessNumberToWordsConverter { @@ -149,7 +153,7 @@ static string RemoveOnePrefix(string toWords) return toWords; } - static bool ExceptionNumbersToWords(long number, out string words) => + static bool ExceptionNumbersToWords(long number, [NotNullWhen(true)] out string? words) => OrdinalExceptions.TryGetValue(number, out words); public override string ConvertToTuple(int number) diff --git a/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs index f55190098..a37050ace 100644 --- a/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class IcelandicNumberToWordsConverter : GenderedNumberToWordsConverter { @@ -14,9 +15,9 @@ class Fact { public long Power { get; set; } public GrammaticalGender Gender { get; set; } - public string Plural { get; set; } - public string Single { get; set; } - public string OrdinalPrefix { get; set; } + public required string Plural { get; set; } + public required string Single { get; set; } + public required string OrdinalPrefix { get; set; } } static readonly Dictionary PowerOfTenMap = new() { @@ -29,11 +30,14 @@ class Fact {15, new(){Power = 1000000000000000 , Single = "einn billjarður", Plural = "billjarðar", OrdinalPrefix = "billjarðast", Gender = GrammaticalGender.Masculine }}, {18, new(){Power = 1000000000000000000 , Single = "ein trilljón", Plural = "trilljónir", OrdinalPrefix = "trilljónast", Gender = GrammaticalGender.Feminine }} }; + static bool IsAndSplitNeeded(int number) => number <= 20 || number % 10 == 0 && number < 100 || number % 100 == 0; + static string GetOrdinalEnding(GrammaticalGender gender) => gender == GrammaticalGender.Masculine ? "i" : "a"; - static void GetUnits(ICollection builder, long number, GrammaticalGender gender) + + static void GetUnits(ICollection builder, long number, GrammaticalGender gender) { if (number is > 0 and < 5) { @@ -51,7 +55,8 @@ static void GetUnits(ICollection builder, long number, GrammaticalGender builder.Add(UnitsMap[number]); } } - static void CollectOrdinalParts(ICollection builder, int threeDigitPart, Fact conversionRule, GrammaticalGender partGender, GrammaticalGender ordinalGender) + + static void CollectOrdinalParts(ICollection builder, int threeDigitPart, Fact conversionRule, GrammaticalGender partGender, GrammaticalGender ordinalGender) { var hundreds = threeDigitPart / 100; var hundredRemainder = threeDigitPart % 100; @@ -116,14 +121,14 @@ static void CollectOrdinalParts(ICollection builder, int threeDigitPart, builder.Add(conversionRule.OrdinalPrefix + GetOrdinalEnding(ordinalGender)); } } - static string CollectOrdinalPartsUnderAHundred(int number, GrammaticalGender gender) + + static string? CollectOrdinalPartsUnderAHundred(int number, GrammaticalGender gender) { - string returnValue = null; if (number is >= 0 and < 20) { if (number == 2) { - returnValue = gender switch + return gender switch { GrammaticalGender.Masculine => "annar", GrammaticalGender.Feminine => "önnur", @@ -133,16 +138,19 @@ static string CollectOrdinalPartsUnderAHundred(int number, GrammaticalGender gen } else { - returnValue = UnitsOrdinalPrefixes[number] + GetOrdinalEnding(gender); + return UnitsOrdinalPrefixes[number] + GetOrdinalEnding(gender); } } - else if (number < 100 && number % 10 == 0) + + if (number < 100 && number % 10 == 0) { - returnValue = TensOrdinalPrefixes[number / 10] + GetOrdinalEnding(gender); + return TensOrdinalPrefixes[number / 10] + GetOrdinalEnding(gender); } - return returnValue; + + return null; } - static void CollectParts(IList parts, ref long number, ref bool needsAnd, Fact rule) + + static void CollectParts(IList parts, ref long number, ref bool needsAnd, Fact rule) { var remainder = number / rule.Power; if (remainder > 0) @@ -157,7 +165,8 @@ static void CollectParts(IList parts, ref long number, ref bool needsAnd needsAnd = true; } } - static void CollectPart(ICollection parts, long number, Fact rule) + + static void CollectPart(ICollection parts, long number, Fact rule) { if (number == 1) { @@ -169,7 +178,8 @@ static void CollectPart(ICollection parts, long number, Fact rule) parts.Add(rule.Plural); } } - static void CollectPartUnderOneThousand(ICollection builder, long number, GrammaticalGender gender) + + static void CollectPartUnderOneThousand(ICollection builder, long number, GrammaticalGender gender) { var hundreds = number / 100; var hundredRemainder = number % 100; @@ -209,14 +219,16 @@ static void CollectPartUnderOneThousand(ICollection builder, long number GetUnits(builder, hundredRemainder, gender); } } - static void CollectOrdinal(IList parts, ref int number, ref bool needsAnd, Fact rule, GrammaticalGender gender) + + static void CollectOrdinal(IList parts, ref int number, ref bool needsAnd, Fact rule, GrammaticalGender gender) { var remainder = number / rule.Power; if (remainder > 0) { number %= (int)rule.Power; - if (number > 0 && (number > 19 || (number % 100 > 10 && number % 100 % 10 == 0))) // https://malfar.arnastofnun.is/grein/65658 + // https://malfar.arnastofnun.is/grein/65658 + if (number > 0 && (number > 19 || (number % 100 > 10 && number % 100 % 10 == 0))) { if (remainder == 1) { @@ -250,7 +262,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn return UnitsMap[number]; } - var parts = new List(); + var parts = new List(); if (number < 0) { parts.Add("mínus"); @@ -281,7 +293,7 @@ public override string ConvertToOrdinal(int number, GrammaticalGender gender) { return UnitsOrdinalPrefixes[number] + GetOrdinalEnding(gender); } - var parts = new List(); + var parts = new List(); var needsAnd = false; CollectOrdinal(parts, ref number, ref needsAnd, PowerOfTenMap[12], gender); From 64cf66eeff9f4a5e856391374e40611193d8e7fa Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 21:56:46 +1100 Subject: [PATCH 11/39] . --- .../NumberToWords/AfrikaansNumberToWordsConverter.cs | 5 ++++- .../NumberToWords/ArabicNumberToWordsConverter.cs | 3 ++- .../NumberToWords/ArmenianNumberToWordsConverter.cs | 7 +++++-- .../NumberToWords/AzerbaijaniNumberToWordsConverter.cs | 3 ++- .../NumberToWords/BanglaNumberToWordsConverter.cs | 7 +++++-- .../BrazilianPortugueseNumberToWordsConverter.cs | 3 ++- .../NumberToWords/BulgarianNumberToWordsConverter.cs | 3 ++- .../CentralKurdishNumberToWordsConverter.cs | 3 ++- .../NumberToWords/ChineseNumberToWordsConverter.cs | 4 +++- .../NumberToWords/CroatianNumberToWordsConverter.cs | 3 ++- .../NumberToWords/CzechNumberToWordsConverter.cs | 3 ++- .../NumberToWords/DefaultNumberToWordsConverter.cs | 3 ++- .../NumberToWords/DutchNumberToWordsConverter.cs | 9 +++++---- .../NumberToWords/FarsiNumberToWordsConverter.cs | 3 ++- .../NumberToWords/FinnishNumberToWordsConverter.cs | 3 ++- .../NumberToWords/FrenchBelgianNumberToWordsConverter.cs | 3 ++- 16 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs index c3eac4bae..6887a922f 100644 --- a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs @@ -1,3 +1,6 @@ +#nullable enable +using System.Diagnostics.CodeAnalysis; + namespace Humanizer { class AfrikaansNumberToWordsConverter : @@ -152,7 +155,7 @@ static string RemoveOnePrefix(string toWords) return toWords; } - static bool ExceptionNumbersToWords(int number, out string words) => + static bool ExceptionNumbersToWords(int number, [NotNullWhen(true)] out string? words) => OrdinalExceptions.TryGetValue(number, out words); } } diff --git a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs index f61ed6808..a50965408 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class ArabicNumberToWordsConverter : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs index 9358718ad..fba43cf20 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs @@ -1,4 +1,7 @@ -namespace Humanizer +#nullable enable +using System.Diagnostics.CodeAnalysis; + +namespace Humanizer { class ArmenianNumberToWordsConverter : GenderlessNumberToWordsConverter @@ -169,7 +172,7 @@ static string RemoveOnePrefix(string toWords) return toWords; } - static bool ExceptionNumbersToWords(long number, out string words) => + static bool ExceptionNumbersToWords(long number, [NotNullWhen(true)] out string? words) => OrdinalExceptions.TryGetValue(number, out words); } } diff --git a/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs index 3a4a105c5..e0fcd836d 100644 --- a/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class AzerbaijaniNumberToWordsConverter : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs index d04cea715..0cb627d39 100644 --- a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs @@ -1,4 +1,7 @@ -namespace Humanizer +#nullable enable +using System.Diagnostics.CodeAnalysis; + +namespace Humanizer { class BanglaNumberToWordsConverter : GenderlessNumberToWordsConverter @@ -110,7 +113,7 @@ public override string Convert(long input) return string.Join(" ", parts); } - static bool ExceptionNumbersToWords(int number, out string words) => + static bool ExceptionNumbersToWords(int number, [NotNullWhen(true)] out string? words) => OrdinalExceptions.TryGetValue(number, out words); } } diff --git a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs index 30c4a9dab..d0e763c99 100644 --- a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class BrazilianPortugueseNumberToWordsConverter : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs index 8e4951b08..73c479837 100644 --- a/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class BulgarianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs index 75467a5a2..c0b55f0f9 100644 --- a/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class CentralKurdishNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs index 9ab7f8714..604a017d1 100644 --- a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs @@ -1,4 +1,6 @@ -namespace Humanizer + +#nullable enable +namespace Humanizer { class ChineseNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs index f71dbda71..56ff75221 100644 --- a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer; +#nullable enable +namespace Humanizer; class CroatianNumberToWordsConverter(CultureInfo culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs index 3e7e3471b..a5eba59d1 100644 --- a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class CzechNumberToWordsConverter(CultureInfo culture) : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs index fec946b60..b8679400c 100644 --- a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class DefaultNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs index 86d72d1ea..056b6dd98 100644 --- a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Dutch spelling of numbers is not really officially regulated. @@ -15,9 +16,9 @@ class DutchNumberToWordsConverter : class Fact { public long Value { get; set; } - public string Name { get; set; } - public string Prefix { get; set; } - public string Postfix { get; set; } + public required string Name { get; set; } + public required string Prefix { get; set; } + public required string Postfix { get; set; } public bool DisplayOneUnit { get; set; } } diff --git a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs index 1e2d0f081..c39b2dfbe 100644 --- a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class FarsiNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs index ebff81760..6f276fd41 100644 --- a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class FinnishNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs index a211e3a23..16de2d7f9 100644 --- a/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class FrenchBelgianNumberToWordsConverter : FrenchNumberToWordsConverterBase { From a82c56e9f5ff39c18065a3257771e5b94464fd0e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 21:58:17 +1100 Subject: [PATCH 12/39] . --- .../NumberToWords/AfrikaansNumberToWordsConverter.cs | 1 - .../NumberToWords/ArmenianNumberToWordsConverter.cs | 1 - .../Localisation/NumberToWords/BanglaNumberToWordsConverter.cs | 1 - .../Localisation/NumberToWords/EnglishNumberToWordsConverter.cs | 2 -- .../Localisation/NumberToWords/TamilNumberToWordsConverter.cs | 1 - src/Humanizer/Localisation/Resources.cs | 1 - 6 files changed, 7 deletions(-) diff --git a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs index 6887a922f..d9c19f850 100644 --- a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs @@ -1,5 +1,4 @@ #nullable enable -using System.Diagnostics.CodeAnalysis; namespace Humanizer { diff --git a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs index fba43cf20..37259710b 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ #nullable enable -using System.Diagnostics.CodeAnalysis; namespace Humanizer { diff --git a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs index 0cb627d39..5e7c81bc1 100644 --- a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs @@ -1,5 +1,4 @@ #nullable enable -using System.Diagnostics.CodeAnalysis; namespace Humanizer { diff --git a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs index fcffc050f..15bd23588 100644 --- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs @@ -1,7 +1,5 @@ #nullable enable -using System.Diagnostics.CodeAnalysis; - namespace Humanizer { class EnglishNumberToWordsConverter : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs index 874d9b04e..6e4ee2980 100644 --- a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs @@ -1,5 +1,4 @@ #nullable enable -using System.Diagnostics.CodeAnalysis; namespace Humanizer { diff --git a/src/Humanizer/Localisation/Resources.cs b/src/Humanizer/Localisation/Resources.cs index 2af69c3e2..a6201dc82 100644 --- a/src/Humanizer/Localisation/Resources.cs +++ b/src/Humanizer/Localisation/Resources.cs @@ -1,5 +1,4 @@ #nullable enable -using System.Diagnostics.CodeAnalysis; using System.Resources; namespace Humanizer From e20ca2ea0c1bd315c06a8be1a9df253f82ca37fa Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:09:33 +1100 Subject: [PATCH 13/39] . --- src/Humanizer/Bytes/ByteRate.cs | 5 ++-- src/Humanizer/Bytes/ByteSize.cs | 3 +- src/Humanizer/Configuration/Configurator.cs | 5 ++-- .../Configuration/LocaliserRegistry.cs | 2 +- src/Humanizer/DateHumanizeExtensions.cs | 19 ++++++------ src/Humanizer/HeadingExtensions.cs | 4 +-- .../DefaultCollectionFormatter.cs | 2 +- src/Humanizer/NumberToWordsExtension.cs | 30 +++++++++---------- src/Humanizer/TimeSpanHumanizeExtensions.cs | 8 ++--- src/Humanizer/TimeUnitToSymbolExtensions.cs | 5 ++-- 10 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/Humanizer/Bytes/ByteRate.cs b/src/Humanizer/Bytes/ByteRate.cs index 1b26dc5aa..1c6e67d9c 100644 --- a/src/Humanizer/Bytes/ByteRate.cs +++ b/src/Humanizer/Bytes/ByteRate.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Class to hold a ByteSize and a measurement interval, for the purpose of calculating the rate of transfer @@ -37,7 +38,7 @@ public string Humanize(TimeUnit timeUnit = TimeUnit.Second) => /// Unit of time to calculate rate for (defaults is per second) /// The string format to use for the number of bytes /// Culture to use. If null, current thread's UI culture is used. - public string Humanize(string format, TimeUnit timeUnit = TimeUnit.Second, CultureInfo culture = null) + public string Humanize(string format, TimeUnit timeUnit = TimeUnit.Second, CultureInfo? culture = null) { var displayInterval = timeUnit switch { diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index 708238f88..044f36a4b 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -20,6 +20,7 @@ //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN //THE SOFTWARE. +#nullable enable using static System.Globalization.NumberStyles; namespace Humanizer @@ -62,7 +63,7 @@ public struct ByteSize(double byteSize) : public string LargestWholeNumberSymbol => GetLargestWholeNumberSymbol(); - public string GetLargestWholeNumberSymbol(IFormatProvider provider = null) + public string GetLargestWholeNumberSymbol(IFormatProvider? provider = null) { var cultureFormatter = Configurator.GetFormatter(provider as CultureInfo); diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index d6c266c7e..e2a909cc4 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Provides a configuration point for Humanizer @@ -48,7 +49,7 @@ public static class Configurator /// The formatter to be used /// /// The culture to retrieve formatter for. Null means that current thread's UI culture should be used. - internal static IFormatter GetFormatter(CultureInfo culture) => + internal static IFormatter GetFormatter(CultureInfo? culture) => Formatters.ResolveForCulture(culture); /// diff --git a/src/Humanizer/Configuration/LocaliserRegistry.cs b/src/Humanizer/Configuration/LocaliserRegistry.cs index e5fd6f817..205b9567e 100644 --- a/src/Humanizer/Configuration/LocaliserRegistry.cs +++ b/src/Humanizer/Configuration/LocaliserRegistry.cs @@ -31,7 +31,7 @@ public TLocaliser ResolveForUiCulture() => /// Gets the localiser for the specified culture /// /// The culture to retrieve localiser for. If not specified, current thread's UI culture is used. - public TLocaliser ResolveForCulture(CultureInfo culture) => + public TLocaliser ResolveForCulture(CultureInfo? culture) => FindLocaliser(culture ?? CultureInfo.CurrentUICulture)(culture); /// diff --git a/src/Humanizer/DateHumanizeExtensions.cs b/src/Humanizer/DateHumanizeExtensions.cs index b4d6f098b..426c05a52 100644 --- a/src/Humanizer/DateHumanizeExtensions.cs +++ b/src/Humanizer/DateHumanizeExtensions.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Humanizes DateTime into human readable sentence @@ -13,7 +14,7 @@ public static class DateHumanizeExtensions /// Date to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this DateTime input, bool? utcDate = null, DateTime? dateToCompareAgainst = null, CultureInfo culture = null) + public static string Humanize(this DateTime input, bool? utcDate = null, DateTime? dateToCompareAgainst = null, CultureInfo? culture = null) { var comparisonBase = dateToCompareAgainst ?? DateTime.UtcNow; utcDate ??= input.Kind != DateTimeKind.Local; @@ -30,7 +31,7 @@ public static string Humanize(this DateTime input, bool? utcDate = null, DateTim /// Date to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this DateTime? input, bool? utcDate = null, DateTime? dateToCompareAgainst = null, CultureInfo culture = null) + public static string Humanize(this DateTime? input, bool? utcDate = null, DateTime? dateToCompareAgainst = null, CultureInfo? culture = null) { if (input.HasValue) { @@ -47,7 +48,7 @@ public static string Humanize(this DateTime? input, bool? utcDate = null, DateTi /// Date to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this DateTimeOffset input, DateTimeOffset? dateToCompareAgainst = null, CultureInfo culture = null) + public static string Humanize(this DateTimeOffset input, DateTimeOffset? dateToCompareAgainst = null, CultureInfo? culture = null) { var comparisonBase = dateToCompareAgainst ?? DateTimeOffset.UtcNow; @@ -61,7 +62,7 @@ public static string Humanize(this DateTimeOffset input, DateTimeOffset? dateToC /// Date to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this DateTimeOffset? input, DateTimeOffset? dateToCompareAgainst = null, CultureInfo culture = null) + public static string Humanize(this DateTimeOffset? input, DateTimeOffset? dateToCompareAgainst = null, CultureInfo? culture = null) { if (input.HasValue) { @@ -79,7 +80,7 @@ public static string Humanize(this DateTimeOffset? input, DateTimeOffset? dateTo /// Date to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this DateOnly input, DateOnly? dateToCompareAgainst = null, CultureInfo culture = null) + public static string Humanize(this DateOnly input, DateOnly? dateToCompareAgainst = null, CultureInfo? culture = null) { var comparisonBase = dateToCompareAgainst ?? DateOnly.FromDateTime(DateTime.UtcNow); return Configurator.DateOnlyHumanizeStrategy.Humanize(input, comparisonBase, culture); @@ -92,7 +93,7 @@ public static string Humanize(this DateOnly input, DateOnly? dateToCompareAgains /// Date to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this DateOnly? input, DateOnly? dateToCompareAgainst = null, CultureInfo culture = null) + public static string Humanize(this DateOnly? input, DateOnly? dateToCompareAgainst = null, CultureInfo? culture = null) { if (input.HasValue) { @@ -110,7 +111,7 @@ public static string Humanize(this DateOnly? input, DateOnly? dateToCompareAgain /// Date to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this TimeOnly input, TimeOnly? timeToCompareAgainst = null, bool useUtc = true, CultureInfo culture = null) + public static string Humanize(this TimeOnly input, TimeOnly? timeToCompareAgainst = null, bool useUtc = true, CultureInfo? culture = null) { var comparisonBase = timeToCompareAgainst ?? TimeOnly.FromDateTime(useUtc ? DateTime.UtcNow : DateTime.Now); @@ -125,7 +126,7 @@ public static string Humanize(this TimeOnly input, TimeOnly? timeToCompareAgains /// Time to compare the input against. If null, current date is used as base /// Culture to use. If null, current thread's UI culture is used. /// distance of time in words - public static string Humanize(this TimeOnly? input, TimeOnly? timeToCompareAgainst = null, bool useUtc = true, CultureInfo culture = null) + public static string Humanize(this TimeOnly? input, TimeOnly? timeToCompareAgainst = null, bool useUtc = true, CultureInfo? culture = null) { if (input.HasValue) { diff --git a/src/Humanizer/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs index 623a9d1dd..5b863653d 100644 --- a/src/Humanizer/HeadingExtensions.cs +++ b/src/Humanizer/HeadingExtensions.cs @@ -35,7 +35,7 @@ public static class HeadingExtensions /// The heading value /// Whether to return a short result or not. /// The culture to return the textual representation in - public static string ToHeading(this double heading, HeadingStyle style = HeadingStyle.Abbreviated, CultureInfo culture = null) + public static string? ToHeading(this double heading, HeadingStyle style = HeadingStyle.Abbreviated, CultureInfo? culture = null) { var val = (int)(heading / 22.5 + .5); @@ -76,7 +76,7 @@ public static double FromAbbreviatedHeading(this string heading) => /// The short textual representation of a heading /// The culture of the heading /// The heading. -1 if the heading could not be parsed. - public static double FromAbbreviatedHeading(this string heading, CultureInfo culture = null) + public static double FromAbbreviatedHeading(this string heading, CultureInfo? culture = null) { if (heading == null) { diff --git a/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs b/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs index cc9b227d4..220cf34d2 100644 --- a/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs +++ b/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs @@ -19,7 +19,7 @@ public string Humanize(IEnumerable collection, Func objectForma public virtual string Humanize(IEnumerable collection, string separator) => Humanize(collection, o => o?.ToString(), separator); - public virtual string Humanize(IEnumerable collection, Func objectFormatter, string separator) + public virtual string Humanize(IEnumerable collection, Func objectFormatter, string separator) { if (collection == null) { diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index bd83912bb..b561d353c 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -10,7 +10,7 @@ public static class NumberToWordsExtension /// /// Number to be turned to ordinal words /// Culture to use. If null, current thread's UI culture is used. - public static string ToOrdinalWords(this int number, CultureInfo culture = null) => + public static string ToOrdinalWords(this int number, CultureInfo? culture = null) => Configurator.GetNumberToWordsConverter(culture).ConvertToOrdinal(number); /// @@ -27,7 +27,7 @@ public static string ToOrdinalWords(this int number, CultureInfo culture = null) /// Form of the word, i.e. abbreviation /// Culture to use. If null, current thread's UI culture is used. /// The number converted into ordinal words - public static string ToOrdinalWords(this int number, WordForm wordForm, CultureInfo culture = null) => + public static string ToOrdinalWords(this int number, WordForm wordForm, CultureInfo? culture = null) => Configurator.GetNumberToWordsConverter(culture).ConvertToOrdinal(number, wordForm); /// @@ -38,7 +38,7 @@ public static string ToOrdinalWords(this int number, WordForm wordForm, CultureI /// Number to be turned to words /// The grammatical gender to use for output words /// Culture to use. If null, current thread's UI culture is used. - public static string ToOrdinalWords(this int number, GrammaticalGender gender, CultureInfo culture = null) => + public static string ToOrdinalWords(this int number, GrammaticalGender gender, CultureInfo? culture = null) => Configurator.GetNumberToWordsConverter(culture).ConvertToOrdinal(number, gender); /// @@ -58,7 +58,7 @@ public static string ToOrdinalWords(this int number, GrammaticalGender gender, C /// Form of the word, i.e. abbreviation /// Culture to use. If null, current thread's UI culture is used. /// The number converted into ordinal words - public static string ToOrdinalWords(this int number, GrammaticalGender gender, WordForm wordForm, CultureInfo culture = null) => + public static string ToOrdinalWords(this int number, GrammaticalGender gender, WordForm wordForm, CultureInfo? culture = null) => Configurator.GetNumberToWordsConverter(culture).ConvertToOrdinal(number, gender, wordForm); /// @@ -66,7 +66,7 @@ public static string ToOrdinalWords(this int number, GrammaticalGender gender, W /// /// Number to be turned to tuple /// Culture to use. If null, current thread's UI culture is used. - public static string ToTuple(this int number, CultureInfo culture = null) => + public static string ToTuple(this int number, CultureInfo? culture = null) => Configurator.GetNumberToWordsConverter(culture).ConvertToTuple(number); /// @@ -74,7 +74,7 @@ public static string ToTuple(this int number, CultureInfo culture = null) => /// /// Number to be turned to words /// Culture to use. If null, current thread's UI culture is used. - public static string ToWords(this int number, CultureInfo culture = null) => + public static string ToWords(this int number, CultureInfo? culture = null) => ((long)number).ToWords(culture); /// @@ -91,7 +91,7 @@ public static string ToWords(this int number, CultureInfo culture = null) => /// Form of the word, i.e. abbreviation /// Culture to use. If null, current thread's UI culture is used. /// The number converted to words - public static string ToWords(this int number, WordForm wordForm, CultureInfo culture = null) => + public static string ToWords(this int number, WordForm wordForm, CultureInfo? culture = null) => ((long)number).ToWords(wordForm, culture); /// @@ -100,7 +100,7 @@ public static string ToWords(this int number, WordForm wordForm, CultureInfo cul /// Number to be turned to words /// To add 'and' before the last number. /// Culture to use. If null, current thread's UI culture is used. - public static string ToWords(this int number, bool addAnd, CultureInfo culture = null) => + public static string ToWords(this int number, bool addAnd, CultureInfo? culture = null) => ((long)number).ToWords(culture, addAnd); /// @@ -118,7 +118,7 @@ public static string ToWords(this int number, bool addAnd, CultureInfo culture = /// Form of the word, i.e. abbreviation /// Culture to use. If null, current thread's UI culture is used. /// The number converted to words - public static string ToWords(this int number, bool addAnd, WordForm wordForm, CultureInfo culture = null) => + public static string ToWords(this int number, bool addAnd, WordForm wordForm, CultureInfo? culture = null) => ((long)number).ToWords(wordForm, culture, addAnd); /// @@ -139,7 +139,7 @@ public static string ToWords(this int number, bool addAnd, WordForm wordForm, Cu /// Number to be turned to words /// The grammatical gender to use for output words /// Culture to use. If null, current thread's UI culture is used. - public static string ToWords(this int number, GrammaticalGender gender, CultureInfo culture = null) => + public static string ToWords(this int number, GrammaticalGender gender, CultureInfo? culture = null) => ((long)number).ToWords(gender, culture); /// @@ -158,7 +158,7 @@ public static string ToWords(this int number, GrammaticalGender gender, CultureI /// The grammatical gender to use for output words /// Culture to use. If null, current thread's UI culture is used. /// The number converted to words - public static string ToWords(this int number, WordForm wordForm, GrammaticalGender gender, CultureInfo culture = null) => + public static string ToWords(this int number, WordForm wordForm, GrammaticalGender gender, CultureInfo? culture = null) => ((long)number).ToWords(wordForm, gender, culture); /// @@ -167,7 +167,7 @@ public static string ToWords(this int number, WordForm wordForm, GrammaticalGend /// Number to be turned to words /// Culture to use. If null, current thread's UI culture is used. /// Whether "and" should be included or not. - public static string ToWords(this long number, CultureInfo culture = null, bool addAnd = true) => + public static string ToWords(this long number, CultureInfo? culture = null, bool addAnd = true) => Configurator.GetNumberToWordsConverter(culture).Convert(number, addAnd); /// @@ -185,7 +185,7 @@ public static string ToWords(this long number, CultureInfo culture = null, bool /// Culture to use. If null, current thread's UI culture is used. /// To add 'and' before the last number /// The number converted to words - public static string ToWords(this long number, WordForm wordForm, CultureInfo culture = null, bool addAnd = false) => + public static string ToWords(this long number, WordForm wordForm, CultureInfo? culture = null, bool addAnd = false) => Configurator.GetNumberToWordsConverter(culture).Convert(number, addAnd, wordForm); /// @@ -207,7 +207,7 @@ public static string ToWords(this long number, WordForm wordForm, CultureInfo cu /// Number to be turned to words /// The grammatical gender to use for output words /// Culture to use. If null, current thread's UI culture is used. - public static string ToWords(this long number, GrammaticalGender gender, CultureInfo culture = null) => + public static string ToWords(this long number, GrammaticalGender gender, CultureInfo? culture = null) => Configurator.GetNumberToWordsConverter(culture).Convert(number, gender); /// @@ -226,7 +226,7 @@ public static string ToWords(this long number, GrammaticalGender gender, Culture /// The grammatical gender to use for output words /// Culture to use. If null, current thread's UI culture is used. /// The number converted to words - public static string ToWords(this long number, WordForm wordForm, GrammaticalGender gender, CultureInfo culture = null) => + public static string ToWords(this long number, WordForm wordForm, GrammaticalGender gender, CultureInfo? culture = null) => Configurator.GetNumberToWordsConverter(culture).Convert(number, wordForm, gender); } } diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index f376f9988..e7763b39d 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -23,7 +23,7 @@ public static class TimeSpanHumanizeExtensions /// The minimum unit of time to output. /// The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used. /// Uses words instead of numbers if true. E.g. one day. - public static string Humanize(this TimeSpan timeSpan, int precision = 1, CultureInfo culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string collectionSeparator = ", ", bool toWords = false) => + public static string Humanize(this TimeSpan timeSpan, int precision = 1, CultureInfo? culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string collectionSeparator = ", ", bool toWords = false) => Humanize(timeSpan, precision, false, culture, maxUnit, minUnit, collectionSeparator, toWords); /// @@ -36,7 +36,7 @@ public static string Humanize(this TimeSpan timeSpan, int precision = 1, Culture /// The minimum unit of time to output. /// The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used. /// Uses words instead of numbers if true. E.g. one day. - public static string Humanize(this TimeSpan timeSpan, int precision, bool countEmptyUnits, CultureInfo culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string collectionSeparator = ", ", bool toWords = false) + public static string Humanize(this TimeSpan timeSpan, int precision, bool countEmptyUnits, CultureInfo? culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string collectionSeparator = ", ", bool toWords = false) { var timeParts = CreateTheTimePartsWithUpperAndLowerLimits(timeSpan, culture, maxUnit, minUnit, toWords); timeParts = SetPrecisionOfTimeSpan(timeParts, precision, countEmptyUnits); @@ -52,7 +52,7 @@ public static string Humanize(this TimeSpan timeSpan, int precision, bool countE /// The maximum unit of time to output. The default value is . /// Uses words instead of numbers if true. E.g. "forty years old". /// Age expression in the given culture/language - public static string ToAge(this TimeSpan timeSpan, CultureInfo culture = null, TimeUnit maxUnit = TimeUnit.Year, bool toWords = false) + public static string ToAge(this TimeSpan timeSpan, CultureInfo? culture = null, TimeUnit maxUnit = TimeUnit.Year, bool toWords = false) { var timeSpanExpression = timeSpan.Humanize(culture: culture, maxUnit: maxUnit, toWords: toWords); @@ -87,7 +87,7 @@ static IEnumerable CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan ti return timeParts; } - static string GetTimeUnitPart(TimeUnit timeUnitToGet, TimeSpan timespan, TimeUnit maximumTimeUnit, TimeUnit minimumTimeUnit, IFormatter cultureFormatter, bool toWords = false) + static string? GetTimeUnitPart(TimeUnit timeUnitToGet, TimeSpan timespan, TimeUnit maximumTimeUnit, TimeUnit minimumTimeUnit, IFormatter cultureFormatter, bool toWords = false) { if (timeUnitToGet <= maximumTimeUnit && timeUnitToGet >= minimumTimeUnit) { diff --git a/src/Humanizer/TimeUnitToSymbolExtensions.cs b/src/Humanizer/TimeUnitToSymbolExtensions.cs index 3f0de114b..ded387d92 100644 --- a/src/Humanizer/TimeUnitToSymbolExtensions.cs +++ b/src/Humanizer/TimeUnitToSymbolExtensions.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Transform a time unit into a symbol; e.g. => "a" @@ -10,7 +11,7 @@ public static class TimeUnitToSymbolExtensions /// /// Unit of time to be turned to a symbol /// Culture to use. If null, current thread's UI culture is used. - public static string ToSymbol(this TimeUnit unit, CultureInfo culture = null) => + public static string ToSymbol(this TimeUnit unit, CultureInfo? culture = null) => Configurator.GetFormatter(culture).TimeUnitHumanize(unit); } } From aa83c9cc9a0660f2fedd17943747f381d3a8df5a Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:24:25 +1100 Subject: [PATCH 14/39] . --- src/Humanizer/Bytes/ByteRate.cs | 2 +- src/Humanizer/Bytes/ByteSize.cs | 8 ++++---- src/Humanizer/Configuration/Configurator.cs | 2 +- .../IDateTimeHumanizeStrategy.cs | 2 +- .../IDateTimeOffsetHumanizeStrategy.cs | 2 +- .../PrecisionDateTimeOffsetHumanizeStrategy.cs | 2 +- src/Humanizer/HeadingExtensions.cs | 3 ++- src/Humanizer/NumberToWordsExtension.cs | 3 ++- src/Humanizer/TimeSpanHumanizeExtensions.cs | 13 +++++++------ 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Humanizer/Bytes/ByteRate.cs b/src/Humanizer/Bytes/ByteRate.cs index 1c6e67d9c..bd28c5bdb 100644 --- a/src/Humanizer/Bytes/ByteRate.cs +++ b/src/Humanizer/Bytes/ByteRate.cs @@ -38,7 +38,7 @@ public string Humanize(TimeUnit timeUnit = TimeUnit.Second) => /// Unit of time to calculate rate for (defaults is per second) /// The string format to use for the number of bytes /// Culture to use. If null, current thread's UI culture is used. - public string Humanize(string format, TimeUnit timeUnit = TimeUnit.Second, CultureInfo? culture = null) + public string Humanize(string? format, TimeUnit timeUnit = TimeUnit.Second, CultureInfo? culture = null) { var displayInterval = timeUnit switch { diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index 044f36a4b..28547e557 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -98,7 +98,7 @@ public string GetLargestWholeNumberSymbol(IFormatProvider? provider = null) public string LargestWholeNumberFullWord => GetLargestWholeNumberFullWord(); - public string GetLargestWholeNumberFullWord(IFormatProvider provider = null) + public string GetLargestWholeNumberFullWord(IFormatProvider? provider = null) { var cultureFormatter = Configurator.GetFormatter(provider as CultureInfo); @@ -208,7 +208,7 @@ public string ToString(string format) => public string ToString(string format, IFormatProvider provider) => ToString(format, provider, toSymbol: true); - string ToString(string format, IFormatProvider provider, bool toSymbol) + string ToString(string? format, IFormatProvider? provider, bool toSymbol) { if (format == null) format = "G"; @@ -285,10 +285,10 @@ string ToString(string format, IFormatProvider provider, bool toSymbol) /// tera) used is the largest metric prefix such that the corresponding /// value is greater than or equal to one. /// - public string ToFullWords(string format = null, IFormatProvider provider = null) => + public string ToFullWords(string? format = null, IFormatProvider? provider = null) => ToString(format, provider, toSymbol: false); - public override bool Equals(object value) + public override bool Equals(object? value) { if (value == null) { diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index e2a909cc4..477c24f10 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -56,7 +56,7 @@ internal static IFormatter GetFormatter(CultureInfo? culture) => /// The converter to be used /// /// The culture to retrieve number to words converter for. Null means that current thread's UI culture should be used. - internal static INumberToWordsConverter GetNumberToWordsConverter(CultureInfo culture) => + internal static INumberToWordsConverter GetNumberToWordsConverter(CultureInfo? culture) => NumberToWordsConverters.ResolveForCulture(culture); /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs index df8ac7232..9c154b040 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs @@ -10,6 +10,6 @@ public interface IDateTimeHumanizeStrategy /// /// Calculates the distance of time in words between two provided dates used for DateTime.Humanize /// - string Humanize(DateTime input, DateTime comparisonBase, CultureInfo culture); + string Humanize(DateTime input, DateTime comparisonBase, CultureInfo? culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs index b3bc49657..b9096afd0 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs @@ -10,6 +10,6 @@ public interface IDateTimeOffsetHumanizeStrategy /// /// Calculates the distance of time in words between two provided dates used for DateTimeOffset.Humanize /// - string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo culture); + string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo? culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs index dc1f63340..2853a1d34 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs @@ -19,7 +19,7 @@ public PrecisionDateTimeOffsetHumanizeStrategy(double precision = .75) => /// /// Returns localized & humanized distance of time between two dates; given a specific precision. /// - public string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo culture) => + public string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.PrecisionHumanize(input.UtcDateTime, comparisonBase.UtcDateTime, _precision, culture); } } diff --git a/src/Humanizer/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs index 5b863653d..69311e0ba 100644 --- a/src/Humanizer/HeadingExtensions.cs +++ b/src/Humanizer/HeadingExtensions.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Style for the cardinal direction humanization diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index b561d353c..368590281 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Transform a number into words; e.g. 1 => one diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index e7763b39d..9b06aae04 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Humanizes TimeSpan into human readable form @@ -62,11 +63,11 @@ public static string ToAge(this TimeSpan timeSpan, CultureInfo? culture = null, return ageExpression; } - static IEnumerable CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan timespan, CultureInfo culture, TimeUnit maxUnit, TimeUnit minUnit, bool toWords = false) + static IEnumerable CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan timespan, CultureInfo? culture, TimeUnit maxUnit, TimeUnit minUnit, bool toWords = false) { var cultureFormatter = Configurator.GetFormatter(culture); var firstValueFound = false; - var timeParts = new List(); + var timeParts = new List(); foreach (var timeUnit in _timeUnits) { @@ -177,7 +178,7 @@ static int GetNormalCaseTimeAsInteger(int timeNumberOfUnits, double totalTimeNum return timeNumberOfUnits; } - static string BuildFormatTimePart(IFormatter cultureFormatter, TimeUnit timeUnitType, int amountOfTimeUnits, bool toWords = false) => + static string? BuildFormatTimePart(IFormatter cultureFormatter, TimeUnit timeUnitType, int amountOfTimeUnits, bool toWords = false) => // Always use positive units to account for negative timespans amountOfTimeUnits != 0 ? cultureFormatter.TimeSpanHumanize(timeUnitType, Math.Abs(amountOfTimeUnits), toWords) @@ -186,7 +187,7 @@ static string BuildFormatTimePart(IFormatter cultureFormatter, TimeUnit timeUnit static List CreateTimePartsWithNoTimeValue(string noTimeValue) => [noTimeValue]; - static bool IsContainingOnlyNullValue(IEnumerable timeParts) => + static bool IsContainingOnlyNullValue(IEnumerable timeParts) => timeParts.Count(x => x != null) == 0; static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, int precision, bool countEmptyUnits) @@ -205,7 +206,7 @@ static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, return timeParts; } - static string ConcatenateTimeSpanParts(IEnumerable timeSpanParts, CultureInfo culture, string collectionSeparator) + static string ConcatenateTimeSpanParts(IEnumerable timeSpanParts, CultureInfo? culture, string collectionSeparator) { if (collectionSeparator == null) { From 4abeb7a04b182477eec43a2b0f5c382bc8357b36 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:34:38 +1100 Subject: [PATCH 15/39] . --- src/Humanizer/Bytes/ByteSize.cs | 8 ++++---- src/Humanizer/Configuration/LocaliserRegistry.cs | 11 ++++++----- .../DateTimeHumanizeAlgorithms.cs | 8 ++++---- .../DefaultDateTimeHumanizeStrategy.cs | 2 +- .../DefaultDateTimeOffsetHumanizeStrategy.cs | 2 +- .../PrecisionDateTimeHumanizeStrategy.cs | 2 +- .../DefaultCollectionFormatter.cs | 5 +++-- src/Humanizer/TimeSpanHumanizeExtensions.cs | 10 ++++------ 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index 28547e557..bf6bf301f 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -205,7 +205,7 @@ public string ToString(IFormatProvider provider) public string ToString(string format) => ToString(format, NumberFormatInfo.CurrentInfo); - public string ToString(string format, IFormatProvider provider) => + public string ToString(string? format, IFormatProvider? provider) => ToString(format, provider, toSymbol: true); string ToString(string? format, IFormatProvider? provider, bool toSymbol) @@ -392,7 +392,7 @@ public ByteSize Subtract(ByteSize bs) => public static bool TryParse(string s, out ByteSize result) => TryParse(s, null, out result); - public static bool TryParse(string s, IFormatProvider formatProvider, out ByteSize result) + public static bool TryParse(string s, IFormatProvider? formatProvider, out ByteSize result) { // Arg checking if (string.IsNullOrWhiteSpace(s)) @@ -491,7 +491,7 @@ public static bool TryParse(string s, IFormatProvider formatProvider, out ByteSi return true; } - static NumberFormatInfo GetNumberFormatInfo(IFormatProvider formatProvider) + static NumberFormatInfo GetNumberFormatInfo(IFormatProvider? formatProvider) { if (formatProvider is NumberFormatInfo numberFormat) return numberFormat; @@ -504,7 +504,7 @@ static NumberFormatInfo GetNumberFormatInfo(IFormatProvider formatProvider) public static ByteSize Parse(string s) => Parse(s, null); - public static ByteSize Parse(string s, IFormatProvider formatProvider) + public static ByteSize Parse(string s, IFormatProvider? formatProvider) { if (s == null) { diff --git a/src/Humanizer/Configuration/LocaliserRegistry.cs b/src/Humanizer/Configuration/LocaliserRegistry.cs index 205b9567e..dac310555 100644 --- a/src/Humanizer/Configuration/LocaliserRegistry.cs +++ b/src/Humanizer/Configuration/LocaliserRegistry.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// A registry of localised system components with their associated locales @@ -6,8 +7,8 @@ public class LocaliserRegistry where TLocaliser : class { - readonly IDictionary> _localisers = new Dictionary>(); - readonly Func _defaultLocaliser; + readonly IDictionary> _localisers = new Dictionary>(); + readonly Func _defaultLocaliser; /// /// Creates a localiser registry with the default localiser set to the provided value @@ -18,7 +19,7 @@ public LocaliserRegistry(TLocaliser defaultLocaliser) => /// /// Creates a localiser registry with the default localiser factory set to the provided value /// - public LocaliserRegistry(Func defaultLocaliser) => + public LocaliserRegistry(Func defaultLocaliser) => _defaultLocaliser = defaultLocaliser; /// @@ -46,7 +47,7 @@ public void Register(string localeCode, TLocaliser localiser) => public void Register(string localeCode, Func localiser) => _localisers[localeCode] = localiser; - Func FindLocaliser(CultureInfo culture) + Func FindLocaliser(CultureInfo culture) { for (var c = culture; !string.IsNullOrEmpty(c?.Name); c = c.Parent) { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs index 9451ade8b..3f6a21df3 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs @@ -10,7 +10,7 @@ static class DateTimeHumanizeAlgorithms /// /// Returns localized & humanized distance of time between two dates; given a specific precision. /// - public static string PrecisionHumanize(DateTime input, DateTime comparisonBase, double precision, CultureInfo culture) + public static string PrecisionHumanize(DateTime input, DateTime comparisonBase, double precision, CultureInfo? culture) { var ts = new TimeSpan(Math.Abs(comparisonBase.Ticks - input.Ticks)); var tense = input > comparisonBase ? Tense.Future : Tense.Past; @@ -42,7 +42,7 @@ public static string PrecisionHumanize(TimeOnly input, TimeOnly comparisonBase, return PrecisionHumanize(ts, tense, precision, culture); } #endif - static string PrecisionHumanize(TimeSpan ts, Tense tense, double precision, CultureInfo culture) + static string PrecisionHumanize(TimeSpan ts, Tense tense, double precision, CultureInfo? culture) { int seconds = ts.Seconds, minutes = ts.Minutes, hours = ts.Hours, days = ts.Days; int years = 0, months = 0; @@ -133,7 +133,7 @@ static string PrecisionHumanize(TimeSpan ts, Tense tense, double precision, Cult /// /// Calculates the distance of time in words between two provided dates /// - public static string DefaultHumanize(DateTime input, DateTime comparisonBase, CultureInfo culture) + public static string DefaultHumanize(DateTime input, DateTime comparisonBase, CultureInfo? culture) { var tense = input > comparisonBase ? Tense.Future : Tense.Past; var ts = new TimeSpan(Math.Abs(comparisonBase.Ticks - input.Ticks)); @@ -174,7 +174,7 @@ public static string DefaultHumanize(TimeOnly input, TimeOnly comparisonBase, Cu } #endif - static string DefaultHumanize(TimeSpan ts, bool sameMonth, int days, Tense tense, CultureInfo culture) + static string DefaultHumanize(TimeSpan ts, bool sameMonth, int days, Tense tense, CultureInfo? culture) { var formatter = Configurator.GetFormatter(culture); diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs index 30ce7f030..2f4e7ef69 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs @@ -9,7 +9,7 @@ public class DefaultDateTimeHumanizeStrategy : IDateTimeHumanizeStrategy /// /// Calculates the distance of time in words between two provided dates /// - public string Humanize(DateTime input, DateTime comparisonBase, CultureInfo culture) => + public string Humanize(DateTime input, DateTime comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.DefaultHumanize(input, comparisonBase, culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs index 61007acd8..2316ce20d 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs @@ -9,7 +9,7 @@ public class DefaultDateTimeOffsetHumanizeStrategy : IDateTimeOffsetHumanizeStra /// /// Calculates the distance of time in words between two provided dates /// - public string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo culture) => + public string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.DefaultHumanize(input.UtcDateTime, comparisonBase.UtcDateTime, culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs index f7af52f30..cbbc41621 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs @@ -19,7 +19,7 @@ public PrecisionDateTimeHumanizeStrategy(double precision = .75) => /// /// Returns localized & humanized distance of time between two dates; given a specific precision. /// - public string Humanize(DateTime input, DateTime comparisonBase, CultureInfo culture) => + public string Humanize(DateTime input, DateTime comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.PrecisionHumanize(input, comparisonBase, _precision, culture); } } diff --git a/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs b/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs index 220cf34d2..c7c00dd3e 100644 --- a/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs +++ b/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { class DefaultCollectionFormatter : ICollectionFormatter { @@ -53,7 +54,7 @@ public string Humanize(IEnumerable collection, Func objectForma separator); } - string HumanizeDisplayStrings(IEnumerable strings, string separator) + string HumanizeDisplayStrings(IEnumerable strings, string separator) { var itemsArray = strings .Select(item => item == null ? string.Empty : item.Trim()) diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index 9b06aae04..fa9cbe92c 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -58,12 +58,10 @@ public static string ToAge(this TimeSpan timeSpan, CultureInfo? culture = null, var timeSpanExpression = timeSpan.Humanize(culture: culture, maxUnit: maxUnit, toWords: toWords); var cultureFormatter = Configurator.GetFormatter(culture); - var ageExpression = string.Format(cultureFormatter.TimeSpanHumanize_Age(), timeSpanExpression); - - return ageExpression; + return string.Format(cultureFormatter.TimeSpanHumanize_Age(), timeSpanExpression); } - static IEnumerable CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan timespan, CultureInfo? culture, TimeUnit maxUnit, TimeUnit minUnit, bool toWords = false) + static IEnumerable CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan timespan, CultureInfo? culture, TimeUnit maxUnit, TimeUnit minUnit, bool toWords = false) { var cultureFormatter = Configurator.GetFormatter(culture); var firstValueFound = false; @@ -184,13 +182,13 @@ static int GetNormalCaseTimeAsInteger(int timeNumberOfUnits, double totalTimeNum ? cultureFormatter.TimeSpanHumanize(timeUnitType, Math.Abs(amountOfTimeUnits), toWords) : null; - static List CreateTimePartsWithNoTimeValue(string noTimeValue) => + static List CreateTimePartsWithNoTimeValue(string noTimeValue) => [noTimeValue]; static bool IsContainingOnlyNullValue(IEnumerable timeParts) => timeParts.Count(x => x != null) == 0; - static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, int precision, bool countEmptyUnits) + static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, int precision, bool countEmptyUnits) { if (!countEmptyUnits) { From 42c43616c3c5d6c81fff5a95f2bbdf748bf49efa Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:42:40 +1100 Subject: [PATCH 16/39] . --- src/Humanizer/Bytes/ByteSize.cs | 8 ++++---- src/Humanizer/Configuration/LocaliserRegistry.cs | 6 +++--- .../DateTimeHumanizeAlgorithms.cs | 8 ++++---- .../DefaultDateOnlyHumanizeStrategy.cs | 2 +- .../DefaultTimeOnlyHumanizeStrategy.cs | 2 +- .../DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs | 2 +- .../DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs | 2 +- .../PrecisionDateOnlyHumanizeStrategy.cs | 2 +- .../PrecisionTimeOnlyHumanizeStrategy.cs | 2 +- src/Humanizer/TimeSpanHumanizeExtensions.cs | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index bf6bf301f..b3db804f3 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -314,7 +314,7 @@ public bool Equals(ByteSize value) => public override int GetHashCode() => Bits.GetHashCode(); - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (obj == null) { @@ -389,10 +389,10 @@ public ByteSize Subtract(ByteSize bs) => public static bool operator >=(ByteSize b1, ByteSize b2) => b1.Bits >= b2.Bits; - public static bool TryParse(string s, out ByteSize result) => + public static bool TryParse(string? s, out ByteSize result) => TryParse(s, null, out result); - public static bool TryParse(string s, IFormatProvider? formatProvider, out ByteSize result) + public static bool TryParse(string? s, IFormatProvider? formatProvider, out ByteSize result) { // Arg checking if (string.IsNullOrWhiteSpace(s)) @@ -417,7 +417,7 @@ public static bool TryParse(string s, IFormatProvider? formatProvider, out ByteS result = new(); // Get the index of the first non-digit character - s = s.TrimStart(); // Protect against leading spaces + s = s!.TrimStart(); // Protect against leading spaces int num; var found = false; diff --git a/src/Humanizer/Configuration/LocaliserRegistry.cs b/src/Humanizer/Configuration/LocaliserRegistry.cs index dac310555..7d8f4d9f4 100644 --- a/src/Humanizer/Configuration/LocaliserRegistry.cs +++ b/src/Humanizer/Configuration/LocaliserRegistry.cs @@ -7,7 +7,7 @@ namespace Humanizer public class LocaliserRegistry where TLocaliser : class { - readonly IDictionary> _localisers = new Dictionary>(); + readonly Dictionary> _localisers = new(); readonly Func _defaultLocaliser; /// @@ -44,14 +44,14 @@ public void Register(string localeCode, TLocaliser localiser) => /// /// Registers the localiser factory for the culture provided /// - public void Register(string localeCode, Func localiser) => + public void Register(string localeCode, Func localiser) => _localisers[localeCode] = localiser; Func FindLocaliser(CultureInfo culture) { for (var c = culture; !string.IsNullOrEmpty(c?.Name); c = c.Parent) { - if (_localisers.TryGetValue(c.Name, out var localiser)) + if (_localisers.TryGetValue(c!.Name, out var localiser)) { return localiser; } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs index 3f6a21df3..9575fec93 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs @@ -22,7 +22,7 @@ public static string PrecisionHumanize(DateTime input, DateTime comparisonBase, /// /// Returns localized & humanized distance of time between two dates; given a specific precision. /// - public static string PrecisionHumanize(DateOnly input, DateOnly comparisonBase, double precision, CultureInfo culture) + public static string PrecisionHumanize(DateOnly input, DateOnly comparisonBase, double precision, CultureInfo? culture) { var diffDays = Math.Abs(comparisonBase.DayOfYear - input.DayOfYear); var ts = new TimeSpan(diffDays, 0, 0, 0); @@ -34,7 +34,7 @@ public static string PrecisionHumanize(DateOnly input, DateOnly comparisonBase, /// /// Returns localized & humanized distance of time between two times; given a specific precision. /// - public static string PrecisionHumanize(TimeOnly input, TimeOnly comparisonBase, double precision, CultureInfo culture) + public static string PrecisionHumanize(TimeOnly input, TimeOnly comparisonBase, double precision, CultureInfo? culture) { var ts = new TimeSpan(Math.Abs(comparisonBase.Ticks - input.Ticks)); var tense = input > comparisonBase ? Tense.Future : Tense.Past; @@ -149,7 +149,7 @@ public static string DefaultHumanize(DateTime input, DateTime comparisonBase, Cu /// /// Calculates the distance of time in words between two provided dates /// - public static string DefaultHumanize(DateOnly input, DateOnly comparisonBase, CultureInfo culture) + public static string DefaultHumanize(DateOnly input, DateOnly comparisonBase, CultureInfo? culture) { var tense = input > comparisonBase ? Tense.Future : Tense.Past; var diffDays = Math.Abs(comparisonBase.DayNumber - input.DayNumber); @@ -165,7 +165,7 @@ public static string DefaultHumanize(DateOnly input, DateOnly comparisonBase, Cu /// /// Calculates the distance of time in words between two provided times /// - public static string DefaultHumanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo culture) + public static string DefaultHumanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo? culture) { var tense = input > comparisonBase ? Tense.Future : Tense.Past; var ts = new TimeSpan(Math.Abs(comparisonBase.Ticks - input.Ticks)); diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs index 87581ad4c..45974a9b4 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs @@ -11,7 +11,7 @@ public class DefaultDateOnlyHumanizeStrategy : IDateOnlyHumanizeStrategy /// /// Calculates the distance of time in words between two provided dates /// - public string Humanize(DateOnly input, DateOnly comparisonBase, CultureInfo culture) => + public string Humanize(DateOnly input, DateOnly comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.DefaultHumanize(input, comparisonBase, culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs index c910f266f..4b9c0dc42 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs @@ -11,7 +11,7 @@ public class DefaultTimeOnlyHumanizeStrategy : ITimeOnlyHumanizeStrategy /// /// Calculates the distance of time in words between two provided times /// - public string Humanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo culture) => + public string Humanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.DefaultHumanize(input, comparisonBase, culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs index dc21c300e..def1110d2 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs @@ -11,7 +11,7 @@ public interface IDateOnlyHumanizeStrategy /// /// Calculates the distance of time in words between two provided dates used for DateOnly.Humanize /// - string Humanize(DateOnly input, DateOnly comparisonBase, CultureInfo culture); + string Humanize(DateOnly input, DateOnly comparisonBase, CultureInfo? culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs index 0baaecdfc..de146b480 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs @@ -12,7 +12,7 @@ public interface ITimeOnlyHumanizeStrategy /// /// Calculates the distance of time in words between two provided dates used for TimeOnly.Humanize /// - string Humanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo culture); + string Humanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo? culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs index 5e5270e19..7e48619a8 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs @@ -21,7 +21,7 @@ public PrecisionDateOnlyHumanizeStrategy(double precision = .75) => /// /// Returns localized & humanized distance of time between two dates; given a specific precision. /// - public string Humanize(DateOnly input, DateOnly comparisonBase, CultureInfo culture) => + public string Humanize(DateOnly input, DateOnly comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.PrecisionHumanize(input, comparisonBase, _precision, culture); } } diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs index f18601c85..3a8949574 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs @@ -21,7 +21,7 @@ public PrecisionTimeOnlyHumanizeStrategy(double precision = .75) => /// /// Returns localized & humanized distance of time between two dates; given a specific precision. /// - public string Humanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo culture) => + public string Humanize(TimeOnly input, TimeOnly comparisonBase, CultureInfo? culture) => DateTimeHumanizeAlgorithms.PrecisionHumanize(input, comparisonBase, _precision, culture); } } diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index fa9cbe92c..dd4578dab 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -188,7 +188,7 @@ static int GetNormalCaseTimeAsInteger(int timeNumberOfUnits, double totalTimeNum static bool IsContainingOnlyNullValue(IEnumerable timeParts) => timeParts.Count(x => x != null) == 0; - static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, int precision, bool countEmptyUnits) + static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, int precision, bool countEmptyUnits) { if (!countEmptyUnits) { From eacb34a0cc80207feb7d245ccf66aa2c749fdd26 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:45:12 +1100 Subject: [PATCH 17/39] . --- src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs | 2 +- src/Humanizer/TimeSpanHumanizeExtensions.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs b/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs index 5e91507ad..167eaa173 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs @@ -113,7 +113,7 @@ public void TryParseWorksWithLotsOfSpaces() => [Fact] public void ParseThrowsOnNull() => - Assert.Throws(() => { ByteSize.Parse(null); }); + Assert.Throws(() => { ByteSize.Parse(null!); }); [Fact] public void ParseBits() => diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index dd4578dab..a2ddc41ad 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -24,7 +24,7 @@ public static class TimeSpanHumanizeExtensions /// The minimum unit of time to output. /// The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used. /// Uses words instead of numbers if true. E.g. one day. - public static string Humanize(this TimeSpan timeSpan, int precision = 1, CultureInfo? culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string collectionSeparator = ", ", bool toWords = false) => + public static string Humanize(this TimeSpan timeSpan, int precision = 1, CultureInfo? culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string? collectionSeparator = ", ", bool toWords = false) => Humanize(timeSpan, precision, false, culture, maxUnit, minUnit, collectionSeparator, toWords); /// @@ -37,7 +37,7 @@ public static string Humanize(this TimeSpan timeSpan, int precision = 1, Culture /// The minimum unit of time to output. /// The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used. /// Uses words instead of numbers if true. E.g. one day. - public static string Humanize(this TimeSpan timeSpan, int precision, bool countEmptyUnits, CultureInfo? culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string collectionSeparator = ", ", bool toWords = false) + public static string Humanize(this TimeSpan timeSpan, int precision, bool countEmptyUnits, CultureInfo? culture = null, TimeUnit maxUnit = TimeUnit.Week, TimeUnit minUnit = TimeUnit.Millisecond, string? collectionSeparator = ", ", bool toWords = false) { var timeParts = CreateTheTimePartsWithUpperAndLowerLimits(timeSpan, culture, maxUnit, minUnit, toWords); timeParts = SetPrecisionOfTimeSpan(timeParts, precision, countEmptyUnits); @@ -204,7 +204,7 @@ static bool IsContainingOnlyNullValue(IEnumerable timeParts) => return timeParts; } - static string ConcatenateTimeSpanParts(IEnumerable timeSpanParts, CultureInfo? culture, string collectionSeparator) + static string ConcatenateTimeSpanParts(IEnumerable timeSpanParts, CultureInfo? culture, string? collectionSeparator) { if (collectionSeparator == null) { From f00b2373f108175151dfb5c02dc0e5fd276c4557 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:50:06 +1100 Subject: [PATCH 18/39] . --- ....Approve_Public_Api.DotNet8_0.verified.txt | 114 +++++++++--------- ...est.Approve_Public_Api.Net4_8.verified.txt | 94 +++++++-------- src/Humanizer/Humanizer.csproj | 1 + src/Humanizer/ToQuantityExtensions.cs | 6 +- .../Truncation/FixedNumberOfWordsTruncator.cs | 2 +- src/Humanizer/Truncation/ITruncator.cs | 2 +- 6 files changed, 110 insertions(+), 109 deletions(-) diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt index 7b867eab4..01f4d1ad1 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt @@ -9,7 +9,7 @@ namespace Humanizer public System.TimeSpan Interval { get; } public Humanizer.ByteSize Size { get; } public string Humanize(Humanizer.TimeUnit timeUnit = 1) { } - public string Humanize(string format, Humanizer.TimeUnit timeUnit = 1, System.Globalization.CultureInfo culture = null) { } + public string Humanize(string? format, Humanizer.TimeUnit timeUnit = 1, System.Globalization.CultureInfo? culture = null) { } } public struct ByteSize : System.IComparable, System.IComparable, System.IEquatable, System.IFormattable { @@ -50,18 +50,18 @@ namespace Humanizer public Humanizer.ByteSize AddMegabytes(double value) { } public Humanizer.ByteSize AddTerabytes(double value) { } public int CompareTo(Humanizer.ByteSize other) { } - public int CompareTo(object obj) { } + public int CompareTo(object? obj) { } public bool Equals(Humanizer.ByteSize value) { } - public override bool Equals(object value) { } + public override bool Equals(object? value) { } public override int GetHashCode() { } - public string GetLargestWholeNumberFullWord(System.IFormatProvider provider = null) { } - public string GetLargestWholeNumberSymbol(System.IFormatProvider provider = null) { } + public string GetLargestWholeNumberFullWord(System.IFormatProvider? provider = null) { } + public string GetLargestWholeNumberSymbol(System.IFormatProvider? provider = null) { } public Humanizer.ByteSize Subtract(Humanizer.ByteSize bs) { } - public string ToFullWords(string format = null, System.IFormatProvider provider = null) { } + public string ToFullWords(string? format = null, System.IFormatProvider? provider = null) { } public override string ToString() { } public string ToString(System.IFormatProvider provider) { } public string ToString(string format) { } - public string ToString(string format, System.IFormatProvider provider) { } + public string ToString(string? format, System.IFormatProvider? provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } public static Humanizer.ByteSize FromGigabytes(double value) { } @@ -69,9 +69,9 @@ namespace Humanizer public static Humanizer.ByteSize FromMegabytes(double value) { } public static Humanizer.ByteSize FromTerabytes(double value) { } public static Humanizer.ByteSize Parse(string s) { } - public static Humanizer.ByteSize Parse(string s, System.IFormatProvider formatProvider) { } - public static bool TryParse(string s, out Humanizer.ByteSize result) { } - public static bool TryParse(string s, System.IFormatProvider formatProvider, out Humanizer.ByteSize result) { } + public static Humanizer.ByteSize Parse(string s, System.IFormatProvider? formatProvider) { } + public static bool TryParse(string? s, out Humanizer.ByteSize result) { } + public static bool TryParse(string? s, System.IFormatProvider? formatProvider, out Humanizer.ByteSize result) { } public static bool operator !=(Humanizer.ByteSize b1, Humanizer.ByteSize b2) { } public static Humanizer.ByteSize operator +(Humanizer.ByteSize b1, Humanizer.ByteSize b2) { } public static Humanizer.ByteSize operator ++(Humanizer.ByteSize b) { } @@ -182,14 +182,14 @@ namespace Humanizer } public static class DateHumanizeExtensions { - public static string Humanize(this System.DateOnly input, System.DateOnly? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateOnly? input, System.DateOnly? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateTimeOffset input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateTimeOffset? input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateTime input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateTime? input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.TimeOnly input, System.TimeOnly? timeToCompareAgainst = default, bool useUtc = true, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.TimeOnly? input, System.TimeOnly? timeToCompareAgainst = default, bool useUtc = true, System.Globalization.CultureInfo culture = null) { } + public static string Humanize(this System.DateOnly input, System.DateOnly? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateOnly? input, System.DateOnly? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateTimeOffset input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateTimeOffset? input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateTime input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateTime? input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.TimeOnly input, System.TimeOnly? timeToCompareAgainst = default, bool useUtc = true, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.TimeOnly? input, System.TimeOnly? timeToCompareAgainst = default, bool useUtc = true, System.Globalization.CultureInfo? culture = null) { } } public static class DateToOrdinalWordsExtensions { @@ -201,17 +201,17 @@ namespace Humanizer public class DefaultDateOnlyHumanizeStrategy : Humanizer.IDateOnlyHumanizeStrategy { public DefaultDateOnlyHumanizeStrategy() { } - public string Humanize(System.DateOnly input, System.DateOnly comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateOnly input, System.DateOnly comparisonBase, System.Globalization.CultureInfo? culture) { } } public class DefaultDateTimeHumanizeStrategy : Humanizer.IDateTimeHumanizeStrategy { public DefaultDateTimeHumanizeStrategy() { } - public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo? culture) { } } public class DefaultDateTimeOffsetHumanizeStrategy : Humanizer.IDateTimeOffsetHumanizeStrategy { public DefaultDateTimeOffsetHumanizeStrategy() { } - public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo? culture) { } } public class DefaultFormatter : Humanizer.IFormatter { @@ -232,7 +232,7 @@ namespace Humanizer public class DefaultTimeOnlyHumanizeStrategy : Humanizer.ITimeOnlyHumanizeStrategy { public DefaultTimeOnlyHumanizeStrategy() { } - public string Humanize(System.TimeOnly input, System.TimeOnly comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.TimeOnly input, System.TimeOnly comparisonBase, System.Globalization.CultureInfo? culture) { } } public static class EnglishArticle { @@ -278,10 +278,10 @@ namespace Humanizer public static class HeadingExtensions { public static double FromAbbreviatedHeading(this string heading) { } - public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo culture = null) { } + public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo? culture = null) { } public static double FromHeadingArrow(this char heading) { } public static double FromHeadingArrow(this string heading) { } - public static string ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo culture = null) { } + public static string? ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo? culture = null) { } public static char ToHeadingArrow(this double heading) { } } public enum HeadingStyle @@ -304,7 +304,7 @@ namespace Humanizer } public interface IDateOnlyHumanizeStrategy { - string Humanize(System.DateOnly input, System.DateOnly comparisonBase, System.Globalization.CultureInfo culture); + string Humanize(System.DateOnly input, System.DateOnly comparisonBase, System.Globalization.CultureInfo? culture); } public interface IDateOnlyToOrdinalWordConverter { @@ -313,11 +313,11 @@ namespace Humanizer } public interface IDateTimeHumanizeStrategy { - string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo culture); + string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo? culture); } public interface IDateTimeOffsetHumanizeStrategy { - string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo culture); + string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo? culture); } public interface IDateToOrdinalWordConverter { @@ -362,7 +362,7 @@ namespace Humanizer } public interface ITimeOnlyHumanizeStrategy { - string Humanize(System.TimeOnly input, System.TimeOnly comparisonBase, System.Globalization.CultureInfo culture); + string Humanize(System.TimeOnly input, System.TimeOnly comparisonBase, System.Globalization.CultureInfo? culture); } public interface ITimeOnlyToClockNotationConverter { @@ -772,11 +772,11 @@ namespace Humanizer public class LocaliserRegistry where TLocaliser : class { - public LocaliserRegistry(System.Func defaultLocaliser) { } + public LocaliserRegistry(System.Func defaultLocaliser) { } public LocaliserRegistry(TLocaliser defaultLocaliser) { } - public void Register(string localeCode, System.Func localiser) { } + public void Register(string localeCode, System.Func localiser) { } public void Register(string localeCode, TLocaliser localiser) { } - public TLocaliser ResolveForCulture(System.Globalization.CultureInfo culture) { } + public TLocaliser ResolveForCulture(System.Globalization.CultureInfo? culture) { } public TLocaliser ResolveForUiCulture() { } } public static class MetricNumeralExtensions @@ -886,21 +886,21 @@ namespace Humanizer } public static class NumberToWordsExtension { - public static string ToOrdinalWords(this int number, System.Globalization.CultureInfo culture = null) { } - public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToOrdinalWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToTuple(this int number, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, bool addAnd, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, System.Globalization.CultureInfo culture = null, bool addAnd = true) { } - public static string ToWords(this int number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, bool addAnd, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null, bool addAnd = false) { } + public static string ToOrdinalWords(this int number, System.Globalization.CultureInfo? culture = null) { } + public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToOrdinalWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToTuple(this int number, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, bool addAnd, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, System.Globalization.CultureInfo? culture = null, bool addAnd = true) { } + public static string ToWords(this int number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, bool addAnd, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null, bool addAnd = false) { } } public class On { @@ -1795,22 +1795,22 @@ namespace Humanizer public class PrecisionDateOnlyHumanizeStrategy : Humanizer.IDateOnlyHumanizeStrategy { public PrecisionDateOnlyHumanizeStrategy(double precision = 0.75) { } - public string Humanize(System.DateOnly input, System.DateOnly comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateOnly input, System.DateOnly comparisonBase, System.Globalization.CultureInfo? culture) { } } public class PrecisionDateTimeHumanizeStrategy : Humanizer.IDateTimeHumanizeStrategy { public PrecisionDateTimeHumanizeStrategy(double precision = 0.75) { } - public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo? culture) { } } public class PrecisionDateTimeOffsetHumanizeStrategy : Humanizer.IDateTimeOffsetHumanizeStrategy { public PrecisionDateTimeOffsetHumanizeStrategy(double precision = 0.75) { } - public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo? culture) { } } public class PrecisionTimeOnlyHumanizeStrategy : Humanizer.ITimeOnlyHumanizeStrategy { public PrecisionTimeOnlyHumanizeStrategy(double precision = 0.75) { } - public string Humanize(System.TimeOnly input, System.TimeOnly comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.TimeOnly input, System.TimeOnly comparisonBase, System.Globalization.CultureInfo? culture) { } } public static class PrepositionsExtensions { @@ -1839,8 +1839,8 @@ namespace Humanizer } public static class Resources { - public static string GetResource(string resourceKey, System.Globalization.CultureInfo culture = null) { } - public static bool TryGetResource(string resourceKey, System.Globalization.CultureInfo culture, out string result) { } + public static string? GetResource(string resourceKey, System.Globalization.CultureInfo? culture = null) { } + public static bool TryGetResource(string resourceKey, System.Globalization.CultureInfo? culture, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? result) { } } public static class RomanNumeralExtensions { @@ -1873,9 +1873,9 @@ namespace Humanizer } public static class TimeSpanHumanizeExtensions { - public static string Humanize(this System.TimeSpan timeSpan, int precision = 1, System.Globalization.CultureInfo culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string collectionSeparator = ", ", bool toWords = false) { } - public static string Humanize(this System.TimeSpan timeSpan, int precision, bool countEmptyUnits, System.Globalization.CultureInfo culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string collectionSeparator = ", ", bool toWords = false) { } - public static string ToAge(this System.TimeSpan timeSpan, System.Globalization.CultureInfo culture = null, Humanizer.TimeUnit maxUnit = 7, bool toWords = false) { } + public static string Humanize(this System.TimeSpan timeSpan, int precision = 1, System.Globalization.CultureInfo? culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string? collectionSeparator = ", ", bool toWords = false) { } + public static string Humanize(this System.TimeSpan timeSpan, int precision, bool countEmptyUnits, System.Globalization.CultureInfo? culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string? collectionSeparator = ", ", bool toWords = false) { } + public static string ToAge(this System.TimeSpan timeSpan, System.Globalization.CultureInfo? culture = null, Humanizer.TimeUnit maxUnit = 7, bool toWords = false) { } } public enum TimeUnit { @@ -1890,7 +1890,7 @@ namespace Humanizer } public static class TimeUnitToSymbolExtensions { - public static string ToSymbol(this Humanizer.TimeUnit unit, System.Globalization.CultureInfo culture = null) { } + public static string ToSymbol(this Humanizer.TimeUnit unit, System.Globalization.CultureInfo? culture = null) { } } public static class To { @@ -1940,7 +1940,7 @@ namespace Humanizer public void AddPlural(string rule, string replacement) { } public void AddSingular(string rule, string replacement) { } public void AddUncountable(string word) { } - public string Pluralize(string word, bool inputIsKnownToBeSingular = true) { } + public string? Pluralize(string word, bool inputIsKnownToBeSingular = true) { } public string Singularize(string word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } } public enum WordForm diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt index 946bb63d7..6ebfc250d 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt @@ -9,7 +9,7 @@ namespace Humanizer public System.TimeSpan Interval { get; } public Humanizer.ByteSize Size { get; } public string Humanize(Humanizer.TimeUnit timeUnit = 1) { } - public string Humanize(string format, Humanizer.TimeUnit timeUnit = 1, System.Globalization.CultureInfo culture = null) { } + public string Humanize(string? format, Humanizer.TimeUnit timeUnit = 1, System.Globalization.CultureInfo? culture = null) { } } public struct ByteSize : System.IComparable, System.IComparable, System.IEquatable, System.IFormattable { @@ -50,18 +50,18 @@ namespace Humanizer public Humanizer.ByteSize AddMegabytes(double value) { } public Humanizer.ByteSize AddTerabytes(double value) { } public int CompareTo(Humanizer.ByteSize other) { } - public int CompareTo(object obj) { } + public int CompareTo(object? obj) { } public bool Equals(Humanizer.ByteSize value) { } - public override bool Equals(object value) { } + public override bool Equals(object? value) { } public override int GetHashCode() { } - public string GetLargestWholeNumberFullWord(System.IFormatProvider provider = null) { } - public string GetLargestWholeNumberSymbol(System.IFormatProvider provider = null) { } + public string GetLargestWholeNumberFullWord(System.IFormatProvider? provider = null) { } + public string GetLargestWholeNumberSymbol(System.IFormatProvider? provider = null) { } public Humanizer.ByteSize Subtract(Humanizer.ByteSize bs) { } - public string ToFullWords(string format = null, System.IFormatProvider provider = null) { } + public string ToFullWords(string? format = null, System.IFormatProvider? provider = null) { } public override string ToString() { } public string ToString(System.IFormatProvider provider) { } public string ToString(string format) { } - public string ToString(string format, System.IFormatProvider provider) { } + public string ToString(string? format, System.IFormatProvider? provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } public static Humanizer.ByteSize FromGigabytes(double value) { } @@ -69,9 +69,9 @@ namespace Humanizer public static Humanizer.ByteSize FromMegabytes(double value) { } public static Humanizer.ByteSize FromTerabytes(double value) { } public static Humanizer.ByteSize Parse(string s) { } - public static Humanizer.ByteSize Parse(string s, System.IFormatProvider formatProvider) { } - public static bool TryParse(string s, out Humanizer.ByteSize result) { } - public static bool TryParse(string s, System.IFormatProvider formatProvider, out Humanizer.ByteSize result) { } + public static Humanizer.ByteSize Parse(string s, System.IFormatProvider? formatProvider) { } + public static bool TryParse(string? s, out Humanizer.ByteSize result) { } + public static bool TryParse(string? s, System.IFormatProvider? formatProvider, out Humanizer.ByteSize result) { } public static bool operator !=(Humanizer.ByteSize b1, Humanizer.ByteSize b2) { } public static Humanizer.ByteSize operator +(Humanizer.ByteSize b1, Humanizer.ByteSize b2) { } public static Humanizer.ByteSize operator ++(Humanizer.ByteSize b) { } @@ -178,10 +178,10 @@ namespace Humanizer } public static class DateHumanizeExtensions { - public static string Humanize(this System.DateTimeOffset input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateTimeOffset? input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateTime input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } - public static string Humanize(this System.DateTime? input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo culture = null) { } + public static string Humanize(this System.DateTimeOffset input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateTimeOffset? input, System.DateTimeOffset? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateTime input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } + public static string Humanize(this System.DateTime? input, bool? utcDate = default, System.DateTime? dateToCompareAgainst = default, System.Globalization.CultureInfo? culture = null) { } } public static class DateToOrdinalWordsExtensions { @@ -191,12 +191,12 @@ namespace Humanizer public class DefaultDateTimeHumanizeStrategy : Humanizer.IDateTimeHumanizeStrategy { public DefaultDateTimeHumanizeStrategy() { } - public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo? culture) { } } public class DefaultDateTimeOffsetHumanizeStrategy : Humanizer.IDateTimeOffsetHumanizeStrategy { public DefaultDateTimeOffsetHumanizeStrategy() { } - public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo? culture) { } } public class DefaultFormatter : Humanizer.IFormatter { @@ -258,10 +258,10 @@ namespace Humanizer public static class HeadingExtensions { public static double FromAbbreviatedHeading(this string heading) { } - public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo culture = null) { } + public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo? culture = null) { } public static double FromHeadingArrow(this char heading) { } public static double FromHeadingArrow(this string heading) { } - public static string ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo culture = null) { } + public static string? ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo? culture = null) { } public static char ToHeadingArrow(this double heading) { } } public enum HeadingStyle @@ -284,11 +284,11 @@ namespace Humanizer } public interface IDateTimeHumanizeStrategy { - string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo culture); + string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo? culture); } public interface IDateTimeOffsetHumanizeStrategy { - string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo culture); + string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo? culture); } public interface IDateToOrdinalWordConverter { @@ -556,11 +556,11 @@ namespace Humanizer public class LocaliserRegistry where TLocaliser : class { - public LocaliserRegistry(System.Func defaultLocaliser) { } + public LocaliserRegistry(System.Func defaultLocaliser) { } public LocaliserRegistry(TLocaliser defaultLocaliser) { } - public void Register(string localeCode, System.Func localiser) { } + public void Register(string localeCode, System.Func localiser) { } public void Register(string localeCode, TLocaliser localiser) { } - public TLocaliser ResolveForCulture(System.Globalization.CultureInfo culture) { } + public TLocaliser ResolveForCulture(System.Globalization.CultureInfo? culture) { } public TLocaliser ResolveForUiCulture() { } } public static class MetricNumeralExtensions @@ -670,21 +670,21 @@ namespace Humanizer } public static class NumberToWordsExtension { - public static string ToOrdinalWords(this int number, System.Globalization.CultureInfo culture = null) { } - public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToOrdinalWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToTuple(this int number, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, bool addAnd, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, System.Globalization.CultureInfo culture = null, bool addAnd = true) { } - public static string ToWords(this int number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this int number, bool addAnd, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } - public static string ToWords(this long number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo culture = null, bool addAnd = false) { } + public static string ToOrdinalWords(this int number, System.Globalization.CultureInfo? culture = null) { } + public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToOrdinalWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToTuple(this int number, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, bool addAnd, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, System.Globalization.CultureInfo? culture = null, bool addAnd = true) { } + public static string ToWords(this int number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this int number, bool addAnd, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, Humanizer.WordForm wordForm, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo? culture = null) { } + public static string ToWords(this long number, Humanizer.WordForm wordForm, System.Globalization.CultureInfo? culture = null, bool addAnd = false) { } } public class On { @@ -1149,12 +1149,12 @@ namespace Humanizer public class PrecisionDateTimeHumanizeStrategy : Humanizer.IDateTimeHumanizeStrategy { public PrecisionDateTimeHumanizeStrategy(double precision = 0.75) { } - public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTime input, System.DateTime comparisonBase, System.Globalization.CultureInfo? culture) { } } public class PrecisionDateTimeOffsetHumanizeStrategy : Humanizer.IDateTimeOffsetHumanizeStrategy { public PrecisionDateTimeOffsetHumanizeStrategy(double precision = 0.75) { } - public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo culture) { } + public string Humanize(System.DateTimeOffset input, System.DateTimeOffset comparisonBase, System.Globalization.CultureInfo? culture) { } } public static class PrepositionsExtensions { @@ -1183,8 +1183,8 @@ namespace Humanizer } public static class Resources { - public static string GetResource(string resourceKey, System.Globalization.CultureInfo culture = null) { } - public static bool TryGetResource(string resourceKey, System.Globalization.CultureInfo culture, out string result) { } + public static string? GetResource(string resourceKey, System.Globalization.CultureInfo? culture = null) { } + public static bool TryGetResource(string resourceKey, System.Globalization.CultureInfo? culture, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? result) { } } public static class RomanNumeralExtensions { @@ -1213,9 +1213,9 @@ namespace Humanizer } public static class TimeSpanHumanizeExtensions { - public static string Humanize(this System.TimeSpan timeSpan, int precision = 1, System.Globalization.CultureInfo culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string collectionSeparator = ", ", bool toWords = false) { } - public static string Humanize(this System.TimeSpan timeSpan, int precision, bool countEmptyUnits, System.Globalization.CultureInfo culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string collectionSeparator = ", ", bool toWords = false) { } - public static string ToAge(this System.TimeSpan timeSpan, System.Globalization.CultureInfo culture = null, Humanizer.TimeUnit maxUnit = 7, bool toWords = false) { } + public static string Humanize(this System.TimeSpan timeSpan, int precision = 1, System.Globalization.CultureInfo? culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string? collectionSeparator = ", ", bool toWords = false) { } + public static string Humanize(this System.TimeSpan timeSpan, int precision, bool countEmptyUnits, System.Globalization.CultureInfo? culture = null, Humanizer.TimeUnit maxUnit = 5, Humanizer.TimeUnit minUnit = 0, string? collectionSeparator = ", ", bool toWords = false) { } + public static string ToAge(this System.TimeSpan timeSpan, System.Globalization.CultureInfo? culture = null, Humanizer.TimeUnit maxUnit = 7, bool toWords = false) { } } public enum TimeUnit { @@ -1230,7 +1230,7 @@ namespace Humanizer } public static class TimeUnitToSymbolExtensions { - public static string ToSymbol(this Humanizer.TimeUnit unit, System.Globalization.CultureInfo culture = null) { } + public static string ToSymbol(this Humanizer.TimeUnit unit, System.Globalization.CultureInfo? culture = null) { } } public static class To { @@ -1280,7 +1280,7 @@ namespace Humanizer public void AddPlural(string rule, string replacement) { } public void AddSingular(string rule, string replacement) { } public void AddUncountable(string word) { } - public string Pluralize(string word, bool inputIsKnownToBeSingular = true) { } + public string? Pluralize(string word, bool inputIsKnownToBeSingular = true) { } public string Singularize(string word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } } public enum WordForm diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 8da21117d..878a7f6e8 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -11,6 +11,7 @@ true embedded CS1573;CS1591 + enable diff --git a/src/Humanizer/ToQuantityExtensions.cs b/src/Humanizer/ToQuantityExtensions.cs index 96424c11e..d2db71980 100644 --- a/src/Humanizer/ToQuantityExtensions.cs +++ b/src/Humanizer/ToQuantityExtensions.cs @@ -57,10 +57,10 @@ public static string ToQuantity(this string input, long quantity, ShowQuantityAs /// "request".ToQuantity(10000, format: "N0") => "10,000 requests" /// "request".ToQuantity(1, format: "N0") => "1 request" /// - public static string ToQuantity(this string input, long quantity, string format, IFormatProvider formatProvider = null) => + public static string ToQuantity(this string input, long quantity, string format, IFormatProvider? formatProvider = null) => input.ToQuantity(quantity, showQuantityAs: ShowQuantityAs.Numeric, format: format, formatProvider: formatProvider); - static string ToQuantity(this string input, long quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric, string format = null, IFormatProvider formatProvider = null) + static string ToQuantity(this string input, long quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric, string? format = null, IFormatProvider? formatProvider = null) { var transformedInput = quantity == 1 ? input.Singularize(inputIsKnownToBePlural: false) @@ -91,7 +91,7 @@ static string ToQuantity(this string input, long quantity, ShowQuantityAs showQu /// "request".ToQuantity(10.6, format: "N0") => "10.6 requests" /// "request".ToQuantity(1.0, format: "N0") => "1 request" /// - public static string ToQuantity(this string input, double quantity, string format = null, IFormatProvider formatProvider = null) + public static string ToQuantity(this string input, double quantity, string? format = null, IFormatProvider formatProvider = null) { var transformedInput = quantity == 1 ? input.Singularize(inputIsKnownToBePlural: false) diff --git a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs index 4271b636c..ef878d860 100644 --- a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs +++ b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs @@ -5,7 +5,7 @@ namespace Humanizer /// class FixedNumberOfWordsTruncator : ITruncator { - public string Truncate(string value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) + public string? Truncate(string? value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) { if (value == null) { diff --git a/src/Humanizer/Truncation/ITruncator.cs b/src/Humanizer/Truncation/ITruncator.cs index 9032613b0..e77871745 100644 --- a/src/Humanizer/Truncation/ITruncator.cs +++ b/src/Humanizer/Truncation/ITruncator.cs @@ -13,6 +13,6 @@ public interface ITruncator /// The string used to truncate with /// The enum value used to determine from where to truncate the string /// The truncated string - string Truncate(string value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right); + string? Truncate(string? value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right); } } From 05a03dc8498c605ff6f4ec8ba257694a8c849ab3 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:51:25 +1100 Subject: [PATCH 19/39] . --- src/Humanizer/Bytes/ByteSize.cs | 4 ++-- src/Humanizer/Bytes/ByteSizeExtensions.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index b3db804f3..8a9c22ea4 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -194,7 +194,7 @@ public static ByteSize FromTerabytes(double value) => public override string ToString() => ToString(NumberFormatInfo.CurrentInfo); - public string ToString(IFormatProvider provider) + public string ToString(IFormatProvider? provider) { if (provider == null) provider = CultureInfo.CurrentCulture; @@ -202,7 +202,7 @@ public string ToString(IFormatProvider provider) return string.Format(provider, "{0:0.##} {1}", LargestWholeNumberValue, GetLargestWholeNumberSymbol(provider)); } - public string ToString(string format) => + public string ToString(string? format) => ToString(format, NumberFormatInfo.CurrentInfo); public string ToString(string? format, IFormatProvider? provider) => diff --git a/src/Humanizer/Bytes/ByteSizeExtensions.cs b/src/Humanizer/Bytes/ByteSizeExtensions.cs index ba3c5f292..ff8d46c97 100644 --- a/src/Humanizer/Bytes/ByteSizeExtensions.cs +++ b/src/Humanizer/Bytes/ByteSizeExtensions.cs @@ -292,7 +292,7 @@ public static ByteSize Terabytes(this long input) => /// Turns a byte quantity into human readable form, eg 2 GB /// /// The string format to use - public static string Humanize(this ByteSize input, string format = null) => + public static string Humanize(this ByteSize input, string? format = null) => string.IsNullOrWhiteSpace(format) ? input.ToString() : input.ToString(format); /// From 0a45b8e0e3b50068c383ecdb51cedd6d4e2f752b Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 22:56:48 +1100 Subject: [PATCH 20/39] . --- src/Humanizer/Bytes/ByteSizeExtensions.cs | 2 +- .../NumberToWords/Italian/ItalianCardinalNumberCruncher.cs | 4 ++-- .../NumberToWords/PolishNumberToWordsConverter.cs | 2 +- src/Humanizer/ToQuantityExtensions.cs | 5 +++-- src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Humanizer/Bytes/ByteSizeExtensions.cs b/src/Humanizer/Bytes/ByteSizeExtensions.cs index ff8d46c97..8db587650 100644 --- a/src/Humanizer/Bytes/ByteSizeExtensions.cs +++ b/src/Humanizer/Bytes/ByteSizeExtensions.cs @@ -307,7 +307,7 @@ public static string Humanize(this ByteSize input, IFormatProvider formatProvide /// /// The string format to use /// The format provider to use - public static string Humanize(this ByteSize input, string format, IFormatProvider formatProvider) => + public static string Humanize(this ByteSize input, string? format, IFormatProvider? formatProvider) => string.IsNullOrWhiteSpace(format) ? input.ToString(formatProvider) : input.ToString(format, formatProvider); /// diff --git a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs index 96961fff0..e30bce85f 100644 --- a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs +++ b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs @@ -57,9 +57,9 @@ protected static List SplitEveryThreeDigits(int number) /// for the next three-digit set. /// /// The next conversion function to use. - public Func GetNextPartConverter() + public Func? GetNextPartConverter() { - Func converter; + Func? converter; switch (_nextSet) { diff --git a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs index 69bf80544..802acdb30 100644 --- a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs @@ -1,7 +1,7 @@ #nullable enable namespace Humanizer { - class PolishNumberToWordsConverter(CultureInfo culture) : + class PolishNumberToWordsConverter(CultureInfo? culture) : GenderedNumberToWordsConverter { static readonly string[] HundredsMap = diff --git a/src/Humanizer/ToQuantityExtensions.cs b/src/Humanizer/ToQuantityExtensions.cs index d2db71980..cde594b55 100644 --- a/src/Humanizer/ToQuantityExtensions.cs +++ b/src/Humanizer/ToQuantityExtensions.cs @@ -1,4 +1,5 @@ -namespace Humanizer +#nullable enable +namespace Humanizer { /// /// Enumerates the ways of displaying a quantity value when converting @@ -91,7 +92,7 @@ static string ToQuantity(this string input, long quantity, ShowQuantityAs showQu /// "request".ToQuantity(10.6, format: "N0") => "10.6 requests" /// "request".ToQuantity(1.0, format: "N0") => "1 request" /// - public static string ToQuantity(this string input, double quantity, string? format = null, IFormatProvider formatProvider = null) + public static string ToQuantity(this string input, double quantity, string? format = null, IFormatProvider? formatProvider = null) { var transformedInput = quantity == 1 ? input.Singularize(inputIsKnownToBePlural: false) diff --git a/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs index 2ca3b0887..d5c70a71f 100644 --- a/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs +++ b/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs @@ -5,7 +5,7 @@ namespace Humanizer /// class FixedNumberOfCharactersTruncator : ITruncator { - public string Truncate(string value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) + public string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) { if (value == null) { From 9be3145960ec8f2822f745ad8a6d7d0e05a2469e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:29:19 +1100 Subject: [PATCH 21/39] . --- .../NumberToWords/CroatianNumberToWordsConverter.cs | 2 +- .../Localisation/NumberToWords/CzechNumberToWordsConverter.cs | 2 +- .../NumberToWords/DefaultNumberToWordsConverter.cs | 4 ++-- .../NumberToWords/HebrewNumberToWordsConverter.cs | 2 +- .../NumberToWords/SerbianCyrlNumberToWordsConverter.cs | 2 +- .../NumberToWords/SerbianNumberToWordsConverter.cs | 2 +- .../NumberToWords/SlovenianNumberToWordsConverter.cs | 2 +- src/Humanizer/Truncation/FixedLengthTruncator.cs | 2 +- src/Humanizer/Truncation/ITruncator.cs | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs index 56ff75221..69e54bffc 100644 --- a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs @@ -1,7 +1,7 @@ #nullable enable namespace Humanizer; -class CroatianNumberToWordsConverter(CultureInfo culture) +class CroatianNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter { static readonly string[] UnitsMap = diff --git a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs index a5eba59d1..31a3c7eeb 100644 --- a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs @@ -1,7 +1,7 @@ #nullable enable namespace Humanizer { - class CzechNumberToWordsConverter(CultureInfo culture) : + class CzechNumberToWordsConverter(CultureInfo? culture) : GenderedNumberToWordsConverter { static readonly string[] BillionsMap = ["miliarda", "miliardy", "miliard"]; diff --git a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs index b8679400c..58cd0ec65 100644 --- a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs @@ -3,13 +3,13 @@ namespace Humanizer { class DefaultNumberToWordsConverter : GenderlessNumberToWordsConverter { - readonly CultureInfo _culture; + readonly CultureInfo? _culture; /// /// Constructor. /// /// Culture to use. - public DefaultNumberToWordsConverter(CultureInfo culture) => + public DefaultNumberToWordsConverter(CultureInfo? culture) => _culture = culture; /// diff --git a/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs index 6377c877c..22018e576 100644 --- a/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs @@ -1,6 +1,6 @@ namespace Humanizer { - class HebrewNumberToWordsConverter(CultureInfo culture) : + class HebrewNumberToWordsConverter(CultureInfo? culture) : GenderedNumberToWordsConverter(GrammaticalGender.Feminine) { static readonly string[] UnitsFeminine = ["אפס", "אחת", "שתיים", "שלוש", "ארבע", "חמש", "שש", "שבע", "שמונה", "תשע", "עשר"]; diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs index bda1ff628..b5b75a8b4 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs @@ -1,7 +1,7 @@ #nullable enable namespace Humanizer { - class SerbianCyrlNumberToWordsConverter(CultureInfo culture) : + class SerbianCyrlNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter { static readonly string[] UnitsMap = ["нула", "један", "два", "три", "четири", "пет", "шест", "седам", "осам", "девет", "десет", "једанест", "дванаест", "тринаест", "четрнаест", "петнаест", "шеснаест", "седамнаест", "осамнаест", "деветнаест"]; diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs index a09c373c9..c5143c144 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs @@ -1,7 +1,7 @@ #nullable enable namespace Humanizer { - class SerbianNumberToWordsConverter(CultureInfo culture) : + class SerbianNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter { static readonly string[] UnitsMap = ["nula", "jedan", "dva", "tri", "četiri", "pet", "šest", "sedam", "osam", "devet", "deset", "jedanaest", "dvanaest", "trinaest", "četrnaest", "petnaest", "šestnaest", "sedemnaest", "osemnaest", "devetnaest"]; diff --git a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs index 7a5f5a672..1f7b0b843 100644 --- a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs @@ -1,7 +1,7 @@ #nullable enable namespace Humanizer { - class SlovenianNumberToWordsConverter(CultureInfo culture) : + class SlovenianNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter { static readonly string[] UnitsMap = ["nič", "ena", "dva", "tri", "štiri", "pet", "šest", "sedem", "osem", "devet", "deset", "enajst", "dvanajst", "trinajst", "štirinajst", "petnajst", "šestnajst", "sedemnajst", "osemnajst", "devetnajst"]; diff --git a/src/Humanizer/Truncation/FixedLengthTruncator.cs b/src/Humanizer/Truncation/FixedLengthTruncator.cs index 81f09b619..79d6efb2a 100644 --- a/src/Humanizer/Truncation/FixedLengthTruncator.cs +++ b/src/Humanizer/Truncation/FixedLengthTruncator.cs @@ -5,7 +5,7 @@ /// class FixedLengthTruncator : ITruncator { - public string Truncate(string value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) + public string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) { if (value == null) { diff --git a/src/Humanizer/Truncation/ITruncator.cs b/src/Humanizer/Truncation/ITruncator.cs index e77871745..d217fefe7 100644 --- a/src/Humanizer/Truncation/ITruncator.cs +++ b/src/Humanizer/Truncation/ITruncator.cs @@ -13,6 +13,6 @@ public interface ITruncator /// The string used to truncate with /// The enum value used to determine from where to truncate the string /// The truncated string - string? Truncate(string? value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right); + string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right); } } From 4fc3d81d9cfc9f934412ea5ec4c9b3a61c22b709 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:31:52 +1100 Subject: [PATCH 22/39] . --- src/Humanizer/TruncateExtensions.cs | 3 ++- src/Humanizer/Truncation/ITruncator.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Humanizer/TruncateExtensions.cs b/src/Humanizer/TruncateExtensions.cs index 6149cbf9e..3faecd4a9 100644 --- a/src/Humanizer/TruncateExtensions.cs +++ b/src/Humanizer/TruncateExtensions.cs @@ -45,7 +45,8 @@ public static string Truncate(this string input, int length, string truncationSt /// The truncator to use /// The enum value used to determine from where to truncate the string /// The truncated string - public static string Truncate(this string input, int length, string truncationString, ITruncator truncator, TruncateFrom from = TruncateFrom.Right) + [return: NotNullIfNotNull(nameof(input))] + public static string? Truncate(this string? input, int length, string? truncationString, ITruncator truncator, TruncateFrom from = TruncateFrom.Right) { if (truncator == null) { diff --git a/src/Humanizer/Truncation/ITruncator.cs b/src/Humanizer/Truncation/ITruncator.cs index d217fefe7..fc6d89efb 100644 --- a/src/Humanizer/Truncation/ITruncator.cs +++ b/src/Humanizer/Truncation/ITruncator.cs @@ -13,6 +13,7 @@ public interface ITruncator /// The string used to truncate with /// The enum value used to determine from where to truncate the string /// The truncated string + [return: NotNullIfNotNull(nameof(value))] string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right); } } From 6a761ae527f3a75fd035bf9e15e53eae721798ca Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:35:34 +1100 Subject: [PATCH 23/39] . --- src/Humanizer/Localisation/Resources.cs | 2 +- src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Humanizer/Localisation/Resources.cs b/src/Humanizer/Localisation/Resources.cs index 0eb9dcbf3..beac3b672 100644 --- a/src/Humanizer/Localisation/Resources.cs +++ b/src/Humanizer/Localisation/Resources.cs @@ -15,7 +15,7 @@ public static class Resources /// The name of the resource to retrieve. /// The culture of the resource to retrieve. If not specified, current thread's UI culture is used. /// The value of the resource localized for the specified culture. - public static string GetResource(string resourceKey, CultureInfo culture = null) + public static string GetResource(string resourceKey, CultureInfo? culture = null) { var resource = ResourceManager.GetString(resourceKey, culture); diff --git a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs index ef878d860..f33ad3315 100644 --- a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs +++ b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs @@ -17,7 +17,7 @@ class FixedNumberOfWordsTruncator : ITruncator return value; } - var numberOfWords = value.Split((char[])null, StringSplitOptions.RemoveEmptyEntries).Count(); + var numberOfWords = value.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries).Count(); if (numberOfWords <= length) { return value; From 6bf9fd296b8c83b289ab0e2e35d36b55cd60d0c5 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:39:04 +1100 Subject: [PATCH 24/39] . --- src/Humanizer/Inflections/Vocabulary.cs | 10 ++++++++-- src/Humanizer/InflectorExtensions.cs | 3 ++- src/Humanizer/MetricNumeralExtensions.cs | 2 +- .../Truncation/FixedNumberOfWordsTruncator.cs | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Humanizer/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs index caf0f778c..32c0c6100 100644 --- a/src/Humanizer/Inflections/Vocabulary.cs +++ b/src/Humanizer/Inflections/Vocabulary.cs @@ -67,7 +67,8 @@ public void AddSingular(string rule, string replacement) => /// /// Word to be pluralized /// Normally you call Pluralize on singular words; but if you're unsure call it with false - public string? Pluralize(string word, bool inputIsKnownToBeSingular = true) + [return: NotNullIfNotNull(nameof(word))] + public string? Pluralize(string? word, bool inputIsKnownToBeSingular = true) { var s = LetterS(word); if (s != null) @@ -102,8 +103,13 @@ public void AddSingular(string rule, string replacement) => /// Word to be singularized /// Normally you call Singularize on plural words; but if you're unsure call it with false /// Skip singularizing single words that have an 's' on the end - public string Singularize(string word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) + [return: NotNullIfNotNull(nameof(word))] + public string? Singularize(string? word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { + if (word == null) + { + return null; + } var s = LetterS(word); if (s != null) { diff --git a/src/Humanizer/InflectorExtensions.cs b/src/Humanizer/InflectorExtensions.cs index 90c5b46e7..cd5fdb685 100644 --- a/src/Humanizer/InflectorExtensions.cs +++ b/src/Humanizer/InflectorExtensions.cs @@ -30,7 +30,8 @@ public static class InflectorExtensions /// /// Word to be pluralized /// Normally you call Pluralize on singular words; but if you're unsure call it with false - public static string Pluralize(this string word, bool inputIsKnownToBeSingular = true) => + [return: NotNullIfNotNull(nameof(word))] + public static string? Pluralize(this string? word, bool inputIsKnownToBeSingular = true) => Vocabularies.Default.Pluralize(word, inputIsKnownToBeSingular); /// diff --git a/src/Humanizer/MetricNumeralExtensions.cs b/src/Humanizer/MetricNumeralExtensions.cs index c9542294c..9b75abee3 100644 --- a/src/Humanizer/MetricNumeralExtensions.cs +++ b/src/Humanizer/MetricNumeralExtensions.cs @@ -314,7 +314,7 @@ static bool IsInvalidMetricNumeral(this string input) return !double.TryParse(isSymbol ? input.Remove(index) : input, out _); } - struct UnitPrefix(string name, string shortScaleWord, string longScaleWord = null) + struct UnitPrefix(string name, string shortScaleWord, string? longScaleWord = null) { public string Name { get; } = name; public string ShortScaleWord { get; } = shortScaleWord; diff --git a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs index f33ad3315..59ea91b63 100644 --- a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs +++ b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs @@ -5,7 +5,8 @@ namespace Humanizer /// class FixedNumberOfWordsTruncator : ITruncator { - public string? Truncate(string? value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) + [return: NotNullIfNotNull(nameof(value))] + public string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) { if (value == null) { From f5d913dcfc85a293d54f2297867a6a790060266f Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:39:44 +1100 Subject: [PATCH 25/39] . --- src/Humanizer/Inflections/Vocabulary.cs | 5 +++++ src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Humanizer/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs index 32c0c6100..5f8200b33 100644 --- a/src/Humanizer/Inflections/Vocabulary.cs +++ b/src/Humanizer/Inflections/Vocabulary.cs @@ -70,6 +70,11 @@ public void AddSingular(string rule, string replacement) => [return: NotNullIfNotNull(nameof(word))] public string? Pluralize(string? word, bool inputIsKnownToBeSingular = true) { + if (word == null) + { + return null; + } + var s = LetterS(word); if (s != null) { diff --git a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs index 59ea91b63..29789d0cd 100644 --- a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs +++ b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs @@ -57,7 +57,7 @@ static string TruncateFromRight(string value, int length, string truncationStrin return value + truncationString; } - static string TruncateFromLeft(string value, int length, string truncationString) + static string TruncateFromLeft(string value, int length, string? truncationString) { var lastCharactersWasWhiteSpace = true; var numberOfWordsProcessed = 0; From 8ab984fda47c951b11f9d99db5c6e565d0862fa1 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:40:15 +1100 Subject: [PATCH 26/39] . --- src/Humanizer/Localisation/Formatters/GermanFormatter.cs | 2 +- src/Humanizer/Localisation/Formatters/IcelandicFormatter.cs | 2 +- src/Humanizer/Localisation/Formatters/LuxembourgishFormatter.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Humanizer/Localisation/Formatters/GermanFormatter.cs b/src/Humanizer/Localisation/Formatters/GermanFormatter.cs index 70c32e315..ea3b735cf 100644 --- a/src/Humanizer/Localisation/Formatters/GermanFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/GermanFormatter.cs @@ -5,6 +5,6 @@ class GermanFormatter() : { /// public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true) => - base.DataUnitHumanize(dataUnit, count, toSymbol)?.TrimEnd('s'); + base.DataUnitHumanize(dataUnit, count, toSymbol).TrimEnd('s'); } } diff --git a/src/Humanizer/Localisation/Formatters/IcelandicFormatter.cs b/src/Humanizer/Localisation/Formatters/IcelandicFormatter.cs index 39301abbe..d6210f371 100644 --- a/src/Humanizer/Localisation/Formatters/IcelandicFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/IcelandicFormatter.cs @@ -7,7 +7,7 @@ class IcelandicFormatter() : readonly CultureInfo localCulture = new(LocaleCode); public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true) => - base.DataUnitHumanize(dataUnit, count, toSymbol)?.TrimEnd('s'); + base.DataUnitHumanize(dataUnit, count, toSymbol).TrimEnd('s'); protected override string Format(string resourceKey, int number, bool toWords = false) { diff --git a/src/Humanizer/Localisation/Formatters/LuxembourgishFormatter.cs b/src/Humanizer/Localisation/Formatters/LuxembourgishFormatter.cs index e6b6919bd..f234f7a8e 100644 --- a/src/Humanizer/Localisation/Formatters/LuxembourgishFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/LuxembourgishFormatter.cs @@ -11,7 +11,7 @@ class LuxembourgishFormatter() : const string EifelerRuleCharacters = "unitedzohay"; public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true) => - base.DataUnitHumanize(dataUnit, count, toSymbol)?.TrimEnd('s'); + base.DataUnitHumanize(dataUnit, count, toSymbol).TrimEnd('s'); public static string ApplyEifelerRule(string word) => word.TrimEnd(EifelerRuleSuffix); From 75548610b44f568f07f2a8982df26b504740e762 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:40:35 +1100 Subject: [PATCH 27/39] . --- src/Humanizer/EnumDehumanizeExtensions.cs | 2 +- src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Humanizer/EnumDehumanizeExtensions.cs b/src/Humanizer/EnumDehumanizeExtensions.cs index 617ac998b..a883431e2 100644 --- a/src/Humanizer/EnumDehumanizeExtensions.cs +++ b/src/Humanizer/EnumDehumanizeExtensions.cs @@ -43,7 +43,7 @@ public static Enum DehumanizeTo(this string input, Type targetEnum, OnNoMatch on var genericMethod = dehumanizeToMethod.MakeGenericMethod(targetEnum); try { - return (Enum) genericMethod.Invoke(null, [input, onNoMatch]); + return (Enum) genericMethod.Invoke(null, [input, onNoMatch])!; } catch (TargetInvocationException exception) { diff --git a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs index 29789d0cd..d32e012ae 100644 --- a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs +++ b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs @@ -29,7 +29,7 @@ class FixedNumberOfWordsTruncator : ITruncator : TruncateFromRight(value, length, truncationString); } - static string TruncateFromRight(string value, int length, string truncationString) + static string TruncateFromRight(string value, int length, string? truncationString) { var lastCharactersWasWhiteSpace = true; var numberOfWordsProcessed = 0; From 55894869dbd6c246f99b0792253bbfb7345cbf54 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:41:13 +1100 Subject: [PATCH 28/39] . --- src/Humanizer/EnumCache.cs | 2 +- .../NumberToWords/Italian/ItalianCardinalNumberCruncher.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Humanizer/EnumCache.cs b/src/Humanizer/EnumCache.cs index de3ed1420..2d5a0440c 100644 --- a/src/Humanizer/EnumCache.cs +++ b/src/Humanizer/EnumCache.cs @@ -62,7 +62,7 @@ static string GetDescription(T input) return caseName.Humanize(); } - static bool TryGetDescription(MemberInfo member, out string description) + static bool TryGetDescription(MemberInfo member, [NotNullWhen(true)] out string? description) { var displayAttribute = member.GetCustomAttribute(); if (displayAttribute != null) diff --git a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs index e30bce85f..2ebe5a6ec 100644 --- a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs +++ b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs @@ -16,7 +16,10 @@ public string Convert() { var partToString = GetNextPartConverter(); - words = partToString(part) + words; + if (partToString != null) + { + words = partToString(part) + words; + } } // remove trailing spaces if there are only millions or billions From 6c4c12fab78e64dfac68776765efe246c3a98e34 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:41:59 +1100 Subject: [PATCH 29/39] Update Vocabulary.cs --- src/Humanizer/Inflections/Vocabulary.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Humanizer/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs index 5f8200b33..98fd37071 100644 --- a/src/Humanizer/Inflections/Vocabulary.cs +++ b/src/Humanizer/Inflections/Vocabulary.cs @@ -146,6 +146,7 @@ public void AddSingular(string rule, string replacement) => return word; } + [return:NotNullIfNotNull(nameof(word))] string? ApplyRules(IList rules, string? word, bool skipFirstRule) { if (word == null) From cc4a84d0d3cb378d2476ef2967bb95cb55986d23 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:44:43 +1100 Subject: [PATCH 30/39] Update RomanianCardinalNumberConverter.cs --- .../Romanian/RomanianCardinalNumberConverter.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs b/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs index 7285d48a6..9db3d61cf 100644 --- a/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs @@ -116,7 +116,11 @@ public string Convert(int number, GrammaticalGender gender) var partToString = GetNextPartConverter(currentSet); - words = partToString(_threeDigitParts[i], gender).Trim() + " " + words.Trim(); + if (partToString != null) + { + words = partToString(_threeDigitParts[i], gender) + .Trim() + " " + words.Trim(); + } } if (prefixMinusSign) @@ -156,9 +160,9 @@ static List SplitEveryThreeDigits(int number) /// to use for the next three-digit set. /// /// The next conversion function to use. - Func GetNextPartConverter(ThreeDigitSets currentSet) + Func? GetNextPartConverter(ThreeDigitSets currentSet) { - Func converter; + Func? converter; switch (currentSet) { From 81a08e94c9daeb4bc535b3ee56a3abf558a7b0c4 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:45:02 +1100 Subject: [PATCH 31/39] Update IndianNumberToWordsConverter.cs --- .../Localisation/NumberToWords/IndianNumberToWordsConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs index 42d4c870f..9b111cc16 100644 --- a/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs @@ -62,7 +62,7 @@ public static string NumberToText( long number) return NumberToText(number / 10000000).Trim() + " crore " + NumberToText(number % 10000000); } - static bool ExceptionNumbersToWords(long number, out string words) => + static bool ExceptionNumbersToWords(long number, [NotNullWhen(true)] out string? words) => OrdinalExceptions.TryGetValue(number, out words); } } From 8cfe3ad0b6ced545c7a8ba133cb51fecb6d1fad9 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:45:22 +1100 Subject: [PATCH 32/39] Update NorwegianBokmalNumberToWordsConverter.cs --- .../NumberToWords/NorwegianBokmalNumberToWordsConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs index b8e2193a3..a9bdabb66 100644 --- a/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs @@ -155,7 +155,7 @@ static string GetUnitValue(int number, bool isOrdinal) return UnitsMap[number]; } - static bool ExceptionNumbersToWords(int number, out string words) => + static bool ExceptionNumbersToWords(int number, [NotNullWhen(true)] out string? words) => OrdinalExceptions.TryGetValue(number, out words); string Part(string pluralFormat, string singular, int number, bool postfixSpace = false) From 508cb8052808fbae26e5c705ea0e152f1ed28509 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:45:45 +1100 Subject: [PATCH 33/39] Update EnumCache.cs --- src/Humanizer/EnumCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Humanizer/EnumCache.cs b/src/Humanizer/EnumCache.cs index 2d5a0440c..8ebd728b6 100644 --- a/src/Humanizer/EnumCache.cs +++ b/src/Humanizer/EnumCache.cs @@ -69,7 +69,7 @@ static bool TryGetDescription(MemberInfo member, [NotNullWhen(true)] out string? { description = displayAttribute.GetDescription() ?? displayAttribute.GetName(); - return true; + return description != null; } foreach (var attr in member.GetCustomAttributes()) From 9e7d7709457a393cea329b35453b0e2812ec3794 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:48:12 +1100 Subject: [PATCH 34/39] . --- src/Humanizer/EnumDehumanizeExtensions.cs | 2 +- src/Humanizer/Inflections/Vocabulary.cs | 3 +-- src/Humanizer/Localisation/Resources.cs | 2 +- src/Humanizer/TruncateExtensions.cs | 6 ++++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Humanizer/EnumDehumanizeExtensions.cs b/src/Humanizer/EnumDehumanizeExtensions.cs index a883431e2..d8a97a4b8 100644 --- a/src/Humanizer/EnumDehumanizeExtensions.cs +++ b/src/Humanizer/EnumDehumanizeExtensions.cs @@ -28,7 +28,7 @@ public static TTargetEnum DehumanizeTo(this string input) DehumanizeToPrivate(input, onNoMatch); static MethodInfo dehumanizeToMethod = typeof(EnumDehumanizeExtensions) - .GetMethod("DehumanizeTo", [typeof(string), typeof(OnNoMatch)]); + .GetMethod("DehumanizeTo", [typeof(string), typeof(OnNoMatch)])!; /// /// Dehumanizes a string into the Enum it was originally Humanized from! diff --git a/src/Humanizer/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs index 98fd37071..ecba6895e 100644 --- a/src/Humanizer/Inflections/Vocabulary.cs +++ b/src/Humanizer/Inflections/Vocabulary.cs @@ -99,7 +99,7 @@ public void AddSingular(string rule, string replacement) => return word; } - return result; + return result!; } /// @@ -146,7 +146,6 @@ public void AddSingular(string rule, string replacement) => return word; } - [return:NotNullIfNotNull(nameof(word))] string? ApplyRules(IList rules, string? word, bool skipFirstRule) { if (word == null) diff --git a/src/Humanizer/Localisation/Resources.cs b/src/Humanizer/Localisation/Resources.cs index beac3b672..765849689 100644 --- a/src/Humanizer/Localisation/Resources.cs +++ b/src/Humanizer/Localisation/Resources.cs @@ -34,7 +34,7 @@ public static string GetResource(string resourceKey, CultureInfo? culture = null /// The culture of the resource to retrieve. If not specified, current thread's UI culture is used. /// The value of the resource localized for the specified culture if found; null otherwise. /// true if the specified string resource was found for the given culture; otherwise, false. - public static bool TryGetResource(string resourceKey, CultureInfo culture, out string result) + public static bool TryGetResource(string resourceKey, CultureInfo? culture, [NotNullWhen(true)] out string? result) { culture ??= CultureInfo.CurrentUICulture; var resourceSet = ResourceManager.GetResourceSet(culture, createIfNotExists: false, tryParents: false); diff --git a/src/Humanizer/TruncateExtensions.cs b/src/Humanizer/TruncateExtensions.cs index 3faecd4a9..f081c896a 100644 --- a/src/Humanizer/TruncateExtensions.cs +++ b/src/Humanizer/TruncateExtensions.cs @@ -22,7 +22,8 @@ public static string Truncate(this string input, int length) => /// The truncate to use /// The enum value used to determine from where to truncate the string /// The truncated string - public static string Truncate(this string input, int length, ITruncator truncator, TruncateFrom from = TruncateFrom.Right) => + [return: NotNullIfNotNull(nameof(input))] + public static string? Truncate(this string? input, int length, ITruncator truncator, TruncateFrom from = TruncateFrom.Right) => input.Truncate(length, "…", truncator, from); /// @@ -33,7 +34,8 @@ public static string Truncate(this string input, int length, ITruncator truncato /// The string used to truncate with /// The enum value used to determine from where to truncate the string /// The truncated string - public static string Truncate(this string input, int length, string truncationString, TruncateFrom from = TruncateFrom.Right) => + [return: NotNullIfNotNull(nameof(input))] + public static string? Truncate(this string? input, int length, string truncationString, TruncateFrom from = TruncateFrom.Right) => input.Truncate(length, truncationString, Truncator.FixedLength, from); /// From 49540800ebbc9b7464d5777487c94b9162bffa6d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:50:58 +1100 Subject: [PATCH 35/39] . --- src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs | 4 ++-- src/Humanizer.Tests.Shared/MetricNumeralTests.cs | 2 +- src/Humanizer/ToQuantityExtensions.cs | 2 +- src/Humanizer/TruncateExtensions.cs | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs b/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs index 9d61fe828..51a12e29d 100644 --- a/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs @@ -101,11 +101,11 @@ public void HumanizeHandlesNullItemsWithoutAnException() => [Fact] public void HumanizeHandlesNullStringDisplayFormatterReturnsWithoutAnException() => - Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => null))); + Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => null!))); [Fact] public void HumanizeHandlesNullObjectDisplayFormatterReturnsWithoutAnException() => - Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => (object?)null))); + Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => (object)null!))); [Fact] public void HumanizeRunsStringDisplayFormatterOnNulls() => diff --git a/src/Humanizer.Tests.Shared/MetricNumeralTests.cs b/src/Humanizer.Tests.Shared/MetricNumeralTests.cs index 873ed2f4a..c85130419 100644 --- a/src/Humanizer.Tests.Shared/MetricNumeralTests.cs +++ b/src/Humanizer.Tests.Shared/MetricNumeralTests.cs @@ -33,7 +33,7 @@ public void FromMetricOnInvalid(string input) => [Fact] public void FromMetricOnNull() => Assert.Throws(() => - MetricNumeralExtensions.FromMetric(null)); + MetricNumeralExtensions.FromMetric(null!)); [Theory] [MemberData(nameof(SymbolRange))] diff --git a/src/Humanizer/ToQuantityExtensions.cs b/src/Humanizer/ToQuantityExtensions.cs index cde594b55..d334be60d 100644 --- a/src/Humanizer/ToQuantityExtensions.cs +++ b/src/Humanizer/ToQuantityExtensions.cs @@ -58,7 +58,7 @@ public static string ToQuantity(this string input, long quantity, ShowQuantityAs /// "request".ToQuantity(10000, format: "N0") => "10,000 requests" /// "request".ToQuantity(1, format: "N0") => "1 request" /// - public static string ToQuantity(this string input, long quantity, string format, IFormatProvider? formatProvider = null) => + public static string ToQuantity(this string input, long quantity, string? format, IFormatProvider? formatProvider = null) => input.ToQuantity(quantity, showQuantityAs: ShowQuantityAs.Numeric, format: format, formatProvider: formatProvider); static string ToQuantity(this string input, long quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric, string? format = null, IFormatProvider? formatProvider = null) diff --git a/src/Humanizer/TruncateExtensions.cs b/src/Humanizer/TruncateExtensions.cs index f081c896a..380b52799 100644 --- a/src/Humanizer/TruncateExtensions.cs +++ b/src/Humanizer/TruncateExtensions.cs @@ -11,7 +11,8 @@ public static class TruncateExtensions /// The string to be truncated /// The length to truncate to /// The truncated string - public static string Truncate(this string input, int length) => + [return: NotNullIfNotNull(nameof(input))] + public static string? Truncate(this string? input, int length) => input.Truncate(length, "…", Truncator.FixedLength); /// @@ -35,7 +36,7 @@ public static string Truncate(this string input, int length) => /// The enum value used to determine from where to truncate the string /// The truncated string [return: NotNullIfNotNull(nameof(input))] - public static string? Truncate(this string? input, int length, string truncationString, TruncateFrom from = TruncateFrom.Right) => + public static string? Truncate(this string? input, int length, string? truncationString, TruncateFrom from = TruncateFrom.Right) => input.Truncate(length, truncationString, Truncator.FixedLength, from); /// From 6401df4ba3103197512026fa7843df19b7d76449 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:54:43 +1100 Subject: [PATCH 36/39] . --- src/Benchmarks/Benchmarks.csproj | 1 - src/Directory.build.props | 1 + ....Approve_Public_Api.DotNet8_0.verified.txt | 38 +++++++++++-------- ...est.Approve_Public_Api.Net4_8.verified.txt | 38 +++++++++++-------- src/Humanizer.Tests/Humanizer.Tests.csproj | 1 - src/Humanizer/ArticlePrefixSort.cs | 4 +- src/Humanizer/Bytes/ByteRate.cs | 3 +- src/Humanizer/Bytes/ByteSize.cs | 1 - .../CollectionFormatterRegistry.cs | 4 +- src/Humanizer/Configuration/Configurator.cs | 3 +- .../Configuration/LocaliserRegistry.cs | 3 +- src/Humanizer/DateHumanizeExtensions.cs | 3 +- .../DateTimeHumanizeAlgorithms.cs | 4 +- .../DefaultDateOnlyHumanizeStrategy.cs | 3 +- .../DefaultDateTimeHumanizeStrategy.cs | 1 - .../DefaultDateTimeOffsetHumanizeStrategy.cs | 1 - .../DefaultTimeOnlyHumanizeStrategy.cs | 3 +- .../IDateOnlyHumanizeStrategy.cs | 3 +- .../IDateTimeHumanizeStrategy.cs | 4 +- .../IDateTimeOffsetHumanizeStrategy.cs | 4 +- .../ITimeOnlyHumanizeStrategy.cs | 4 +- .../PrecisionDateOnlyHumanizeStrategy.cs | 4 +- .../PrecisionDateTimeHumanizeStrategy.cs | 2 - ...PrecisionDateTimeOffsetHumanizeStrategy.cs | 2 - .../PrecisionTimeOnlyHumanizeStrategy.cs | 4 +- .../FluentDate/PrepositionsExtensions.cs | 3 +- src/Humanizer/HeadingExtensions.cs | 3 +- src/Humanizer/Humanizer.csproj | 1 - src/Humanizer/Inflections/Vocabularies.cs | 3 +- src/Humanizer/Inflections/Vocabulary.cs | 3 +- .../DefaultCollectionFormatter.cs | 3 +- .../AfrikaansNumberToWordsConverter.cs | 2 - .../ArabicNumberToWordsConverter.cs | 3 +- .../ArmenianNumberToWordsConverter.cs | 4 +- .../AzerbaijaniNumberToWordsConverter.cs | 3 +- .../BanglaNumberToWordsConverter.cs | 4 +- ...azilianPortugueseNumberToWordsConverter.cs | 3 +- .../BulgarianNumberToWordsConverter.cs | 3 +- .../CentralKurdishNumberToWordsConverter.cs | 3 +- .../ChineseNumberToWordsConverter.cs | 4 +- .../CroatianNumberToWordsConverter.cs | 3 +- .../CzechNumberToWordsConverter.cs | 3 +- .../DefaultNumberToWordsConverter.cs | 3 +- .../DutchNumberToWordsConverter.cs | 3 +- .../EnglishNumberToWordsConverter.cs | 4 +- .../FarsiNumberToWordsConverter.cs | 3 +- .../FinnishNumberToWordsConverter.cs | 3 +- .../FrenchBelgianNumberToWordsConverter.cs | 3 +- .../IcelandicNumberToWordsConverter.cs | 3 +- .../LithuanianNumberToWordsConverter.cs | 3 +- .../LuxembourgishNumberToWordsConverter.cs | 3 +- .../MalteseNumberToWordsConvertor.cs | 3 +- .../PolishNumberToWordsConverter.cs | 3 +- .../PortugueseNumberToWordsConverter.cs | 3 +- .../RomanianNumberToWordsConverter.cs | 3 +- .../RussianNumberToWordsConverter.cs | 3 +- .../SerbianCyrlNumberToWordsConverter.cs | 3 +- .../SerbianNumberToWordsConverter.cs | 3 +- .../SlovenianNumberToWordsConverter.cs | 3 +- .../SpanishNumberToWordsConverter.cs | 3 +- .../SwedishNumberToWordsConverter.cs | 3 +- .../TamilNumberToWordsConverter.cs | 4 +- .../TurkishNumberToWordConverter.cs | 3 +- .../UkrainianNumberToWordsConverter.cs | 3 +- .../UzbekCyrlNumberToWordConverter.cs | 3 +- .../UzbekLatnNumberToWordConverter.cs | 3 +- .../VietnameseNumberToWordsConverter.cs | 3 +- .../Ordinalizers/ArmenianOrdinalizer.cs | 3 +- .../Ordinalizers/AzerbaijaniOrdinalizer.cs | 3 +- .../Ordinalizers/DefaultOrdinalizer.cs | 4 +- .../Ordinalizers/FrenchOrdinalizer.cs | 3 +- .../Localisation/Ordinalizers/IOrdinalizer.cs | 3 +- .../Ordinalizers/RomanianOrdinalizer.cs | 4 +- .../Ordinalizers/SpanishOrdinalizer.cs | 3 +- .../Ordinalizers/UkrainianOrdinalizer.cs | 3 +- .../ResourceKeys.TimeSpanHumanize.cs | 3 +- .../ResourceKeys.TimeUnitSymbol.cs | 3 +- src/Humanizer/Localisation/Tense.cs | 3 +- src/Humanizer/Localisation/TimeUnit.cs | 3 +- src/Humanizer/NumberToWordsExtension.cs | 3 +- src/Humanizer/TimeSpanHumanizeExtensions.cs | 3 +- src/Humanizer/TimeUnitToSymbolExtensions.cs | 3 +- src/Humanizer/ToQuantityExtensions.cs | 3 +- .../Transformer/ICulturedStringTransformer.cs | 3 +- .../Transformer/IStringTransformer.cs | 2 - src/Humanizer/Transformer/ToLowerCase.cs | 1 - src/Humanizer/Transformer/ToSentenceCase.cs | 3 +- src/Humanizer/Transformer/ToTitleCase.cs | 3 +- src/Humanizer/Transformer/ToUpperCase.cs | 3 +- 89 files changed, 122 insertions(+), 210 deletions(-) diff --git a/src/Benchmarks/Benchmarks.csproj b/src/Benchmarks/Benchmarks.csproj index 8f9f79f9e..98c0251e3 100644 --- a/src/Benchmarks/Benchmarks.csproj +++ b/src/Benchmarks/Benchmarks.csproj @@ -3,7 +3,6 @@ Exe net8.0 - enable diff --git a/src/Directory.build.props b/src/Directory.build.props index 452e57466..616ebace5 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -8,6 +8,7 @@ true true $(SolutionDir)Humanizer.snk + enable diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt index 01f4d1ad1..f0ed3bf0c 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt @@ -59,8 +59,8 @@ namespace Humanizer public Humanizer.ByteSize Subtract(Humanizer.ByteSize bs) { } public string ToFullWords(string? format = null, System.IFormatProvider? provider = null) { } public override string ToString() { } - public string ToString(System.IFormatProvider provider) { } - public string ToString(string format) { } + public string ToString(System.IFormatProvider? provider) { } + public string ToString(string? format) { } public string ToString(string? format, System.IFormatProvider? provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } @@ -110,8 +110,8 @@ namespace Humanizer public static Humanizer.ByteSize Gigabytes(this uint input) { } public static Humanizer.ByteSize Gigabytes(this ushort input) { } public static string Humanize(this Humanizer.ByteSize input, System.IFormatProvider formatProvider) { } - public static string Humanize(this Humanizer.ByteSize input, string format = null) { } - public static string Humanize(this Humanizer.ByteSize input, string format, System.IFormatProvider formatProvider) { } + public static string Humanize(this Humanizer.ByteSize input, string? format = null) { } + public static string Humanize(this Humanizer.ByteSize input, string? format, System.IFormatProvider? formatProvider) { } public static Humanizer.ByteSize Kilobytes(this byte input) { } public static Humanizer.ByteSize Kilobytes(this double input) { } public static Humanizer.ByteSize Kilobytes(this int input) { } @@ -370,7 +370,8 @@ namespace Humanizer } public interface ITruncator { - string Truncate(string value, int length, string truncationString, Humanizer.TruncateFrom truncateFrom = 1); + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("value")] + string? Truncate(string? value, int length, string? truncationString, Humanizer.TruncateFrom truncateFrom = 1); } public class In { @@ -757,7 +758,8 @@ namespace Humanizer public static string Hyphenate(this string underscoredWord) { } public static string Kebaberize(this string input) { } public static string Pascalize(this string input) { } - public static string Pluralize(this string word, bool inputIsKnownToBeSingular = true) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("word")] + public static string? Pluralize(this string? word, bool inputIsKnownToBeSingular = true) { } public static string Singularize(this string word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } public static string Titleize(this string input) { } public static string Underscore(this string input) { } @@ -1839,7 +1841,7 @@ namespace Humanizer } public static class Resources { - public static string? GetResource(string resourceKey, System.Globalization.CultureInfo? culture = null) { } + public static string GetResource(string resourceKey, System.Globalization.CultureInfo? culture = null) { } public static bool TryGetResource(string resourceKey, System.Globalization.CultureInfo? culture, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? result) { } } public static class RomanNumeralExtensions @@ -1905,15 +1907,19 @@ namespace Humanizer { public static string ToQuantity(this string input, double quantity) { } public static string ToQuantity(this string input, long quantity, Humanizer.ShowQuantityAs showQuantityAs = 1) { } - public static string ToQuantity(this string input, double quantity, string format = null, System.IFormatProvider formatProvider = null) { } - public static string ToQuantity(this string input, long quantity, string format, System.IFormatProvider formatProvider = null) { } + public static string ToQuantity(this string input, double quantity, string? format = null, System.IFormatProvider? formatProvider = null) { } + public static string ToQuantity(this string input, long quantity, string? format, System.IFormatProvider? formatProvider = null) { } } public static class TruncateExtensions { - public static string Truncate(this string input, int length) { } - public static string Truncate(this string input, int length, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } - public static string Truncate(this string input, int length, string truncationString, Humanizer.TruncateFrom from = 1) { } - public static string Truncate(this string input, int length, string truncationString, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length, string? truncationString, Humanizer.TruncateFrom from = 1) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length, string? truncationString, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } } public enum TruncateFrom { @@ -1940,8 +1946,10 @@ namespace Humanizer public void AddPlural(string rule, string replacement) { } public void AddSingular(string rule, string replacement) { } public void AddUncountable(string word) { } - public string? Pluralize(string word, bool inputIsKnownToBeSingular = true) { } - public string Singularize(string word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("word")] + public string? Pluralize(string? word, bool inputIsKnownToBeSingular = true) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("word")] + public string? Singularize(string? word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } } public enum WordForm { diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt index 6ebfc250d..9ee2eb303 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt @@ -59,8 +59,8 @@ namespace Humanizer public Humanizer.ByteSize Subtract(Humanizer.ByteSize bs) { } public string ToFullWords(string? format = null, System.IFormatProvider? provider = null) { } public override string ToString() { } - public string ToString(System.IFormatProvider provider) { } - public string ToString(string format) { } + public string ToString(System.IFormatProvider? provider) { } + public string ToString(string? format) { } public string ToString(string? format, System.IFormatProvider? provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } @@ -110,8 +110,8 @@ namespace Humanizer public static Humanizer.ByteSize Gigabytes(this uint input) { } public static Humanizer.ByteSize Gigabytes(this ushort input) { } public static string Humanize(this Humanizer.ByteSize input, System.IFormatProvider formatProvider) { } - public static string Humanize(this Humanizer.ByteSize input, string format = null) { } - public static string Humanize(this Humanizer.ByteSize input, string format, System.IFormatProvider formatProvider) { } + public static string Humanize(this Humanizer.ByteSize input, string? format = null) { } + public static string Humanize(this Humanizer.ByteSize input, string? format, System.IFormatProvider? formatProvider) { } public static Humanizer.ByteSize Kilobytes(this byte input) { } public static Humanizer.ByteSize Kilobytes(this double input) { } public static Humanizer.ByteSize Kilobytes(this int input) { } @@ -333,7 +333,8 @@ namespace Humanizer } public interface ITruncator { - string Truncate(string value, int length, string truncationString, Humanizer.TruncateFrom truncateFrom = 1); + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("value")] + string? Truncate(string? value, int length, string? truncationString, Humanizer.TruncateFrom truncateFrom = 1); } public class In { @@ -541,7 +542,8 @@ namespace Humanizer public static string Hyphenate(this string underscoredWord) { } public static string Kebaberize(this string input) { } public static string Pascalize(this string input) { } - public static string Pluralize(this string word, bool inputIsKnownToBeSingular = true) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("word")] + public static string? Pluralize(this string? word, bool inputIsKnownToBeSingular = true) { } public static string Singularize(this string word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } public static string Titleize(this string input) { } public static string Underscore(this string input) { } @@ -1183,7 +1185,7 @@ namespace Humanizer } public static class Resources { - public static string? GetResource(string resourceKey, System.Globalization.CultureInfo? culture = null) { } + public static string GetResource(string resourceKey, System.Globalization.CultureInfo? culture = null) { } public static bool TryGetResource(string resourceKey, System.Globalization.CultureInfo? culture, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? result) { } } public static class RomanNumeralExtensions @@ -1245,15 +1247,19 @@ namespace Humanizer { public static string ToQuantity(this string input, double quantity) { } public static string ToQuantity(this string input, long quantity, Humanizer.ShowQuantityAs showQuantityAs = 1) { } - public static string ToQuantity(this string input, double quantity, string format = null, System.IFormatProvider formatProvider = null) { } - public static string ToQuantity(this string input, long quantity, string format, System.IFormatProvider formatProvider = null) { } + public static string ToQuantity(this string input, double quantity, string? format = null, System.IFormatProvider? formatProvider = null) { } + public static string ToQuantity(this string input, long quantity, string? format, System.IFormatProvider? formatProvider = null) { } } public static class TruncateExtensions { - public static string Truncate(this string input, int length) { } - public static string Truncate(this string input, int length, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } - public static string Truncate(this string input, int length, string truncationString, Humanizer.TruncateFrom from = 1) { } - public static string Truncate(this string input, int length, string truncationString, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length, string? truncationString, Humanizer.TruncateFrom from = 1) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public static string? Truncate(this string? input, int length, string? truncationString, Humanizer.ITruncator truncator, Humanizer.TruncateFrom from = 1) { } } public enum TruncateFrom { @@ -1280,8 +1286,10 @@ namespace Humanizer public void AddPlural(string rule, string replacement) { } public void AddSingular(string rule, string replacement) { } public void AddUncountable(string word) { } - public string? Pluralize(string word, bool inputIsKnownToBeSingular = true) { } - public string Singularize(string word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("word")] + public string? Pluralize(string? word, bool inputIsKnownToBeSingular = true) { } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("word")] + public string? Singularize(string? word, bool inputIsKnownToBePlural = true, bool skipSimpleWords = false) { } } public enum WordForm { diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index a8c647901..e86c7d54c 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -1,7 +1,6 @@  net8.0;net48 - enable diff --git a/src/Humanizer/ArticlePrefixSort.cs b/src/Humanizer/ArticlePrefixSort.cs index 0cd65f682..3930ddc48 100644 --- a/src/Humanizer/ArticlePrefixSort.cs +++ b/src/Humanizer/ArticlePrefixSort.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { /// /// Contains methods for removing, appending and prepending article prefixes for sorting strings ignoring the article. diff --git a/src/Humanizer/Bytes/ByteRate.cs b/src/Humanizer/Bytes/ByteRate.cs index bd28c5bdb..62035ec00 100644 --- a/src/Humanizer/Bytes/ByteRate.cs +++ b/src/Humanizer/Bytes/ByteRate.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Class to hold a ByteSize and a measurement interval, for the purpose of calculating the rate of transfer diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index 8a9c22ea4..39bccd607 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -20,7 +20,6 @@ //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN //THE SOFTWARE. -#nullable enable using static System.Globalization.NumberStyles; namespace Humanizer diff --git a/src/Humanizer/Configuration/CollectionFormatterRegistry.cs b/src/Humanizer/Configuration/CollectionFormatterRegistry.cs index 1d834ad8a..f1b66209b 100644 --- a/src/Humanizer/Configuration/CollectionFormatterRegistry.cs +++ b/src/Humanizer/Configuration/CollectionFormatterRegistry.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { class CollectionFormatterRegistry : LocaliserRegistry { diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index 2bb38725a..db8ef4571 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Provides a configuration point for Humanizer diff --git a/src/Humanizer/Configuration/LocaliserRegistry.cs b/src/Humanizer/Configuration/LocaliserRegistry.cs index 7d8f4d9f4..6efc8141d 100644 --- a/src/Humanizer/Configuration/LocaliserRegistry.cs +++ b/src/Humanizer/Configuration/LocaliserRegistry.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// A registry of localised system components with their associated locales diff --git a/src/Humanizer/DateHumanizeExtensions.cs b/src/Humanizer/DateHumanizeExtensions.cs index 426c05a52..89708f195 100644 --- a/src/Humanizer/DateHumanizeExtensions.cs +++ b/src/Humanizer/DateHumanizeExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Humanizes DateTime into human readable sentence diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs index 9575fec93..b61eedf33 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { /// /// Algorithms used to convert distance between two dates into words. diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs index 45974a9b4..3f941ecb0 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs @@ -1,5 +1,4 @@ -#nullable enable -#if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs index 2f4e7ef69..dc96c1ed6 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs @@ -1,4 +1,3 @@ -#nullable enable namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs index 2316ce20d..96f178b9d 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs @@ -1,4 +1,3 @@ -#nullable enable namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs index 4b9c0dc42..ab180a38a 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs @@ -1,5 +1,4 @@ -#nullable enable -#if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs index def1110d2..306e4affb 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs @@ -1,5 +1,4 @@ -#nullable enable -#if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs index 9c154b040..f5bd2a933 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { /// /// Implement this interface to create a new strategy for DateTime.Humanize and hook it in the Configurator.DateTimeHumanizeStrategy diff --git a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs index b9096afd0..5c13a28b4 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { /// /// Implement this interface to create a new strategy for DateTime.Humanize and hook it in the Configurator.DateTimeOffsetHumanizeStrategy diff --git a/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs index de146b480..af44db8c3 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs @@ -1,6 +1,4 @@ -#nullable enable - -#if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs index 7e48619a8..aa543db1d 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs @@ -1,6 +1,4 @@ -#nullable enable - -#if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs index cbbc41621..653a06d62 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs index 2853a1d34..220ee6857 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Humanizer { /// diff --git a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs index 3a8949574..6f1c19261 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs @@ -1,6 +1,4 @@ -#nullable enable - -#if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER namespace Humanizer { diff --git a/src/Humanizer/FluentDate/PrepositionsExtensions.cs b/src/Humanizer/FluentDate/PrepositionsExtensions.cs index 30e9a40aa..85b94a4c4 100644 --- a/src/Humanizer/FluentDate/PrepositionsExtensions.cs +++ b/src/Humanizer/FluentDate/PrepositionsExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// extensions related to spatial or temporal relations diff --git a/src/Humanizer/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs index 69311e0ba..5b863653d 100644 --- a/src/Humanizer/HeadingExtensions.cs +++ b/src/Humanizer/HeadingExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Style for the cardinal direction humanization diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 878a7f6e8..8da21117d 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -11,7 +11,6 @@ true embedded CS1573;CS1591 - enable diff --git a/src/Humanizer/Inflections/Vocabularies.cs b/src/Humanizer/Inflections/Vocabularies.cs index 323ee5717..143eb4fb7 100644 --- a/src/Humanizer/Inflections/Vocabularies.cs +++ b/src/Humanizer/Inflections/Vocabularies.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Container for registered Vocabularies. At present, only a single vocabulary is supported: Default. diff --git a/src/Humanizer/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs index ecba6895e..392f96eea 100644 --- a/src/Humanizer/Inflections/Vocabulary.cs +++ b/src/Humanizer/Inflections/Vocabulary.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer; +namespace Humanizer; /// /// A container for exceptions to simple pluralization/singularization rules. diff --git a/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs b/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs index c7c00dd3e..78bae6ee2 100644 --- a/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs +++ b/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class DefaultCollectionFormatter : ICollectionFormatter { diff --git a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs index d9c19f850..94c0198c1 100644 --- a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Humanizer { class AfrikaansNumberToWordsConverter : diff --git a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs index a50965408..f61ed6808 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class ArabicNumberToWordsConverter : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs index 37259710b..a0b405732 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { class ArmenianNumberToWordsConverter : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs index e0fcd836d..3a4a105c5 100644 --- a/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class AzerbaijaniNumberToWordsConverter : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs index 5e7c81bc1..1df5580ef 100644 --- a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { class BanglaNumberToWordsConverter : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs index d0e763c99..30c4a9dab 100644 --- a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class BrazilianPortugueseNumberToWordsConverter : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs index 2d5f3a27d..3d5b090d7 100644 --- a/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class BulgarianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs index c0b55f0f9..75467a5a2 100644 --- a/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class CentralKurdishNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs index 604a017d1..9ab7f8714 100644 --- a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs @@ -1,6 +1,4 @@ - -#nullable enable -namespace Humanizer +namespace Humanizer { class ChineseNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs index 69e54bffc..9c5bbde40 100644 --- a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer; +namespace Humanizer; class CroatianNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs index 31a3c7eeb..ab39ab84f 100644 --- a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class CzechNumberToWordsConverter(CultureInfo? culture) : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs index 58cd0ec65..f5619c34d 100644 --- a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class DefaultNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs index 056b6dd98..8a3f7f515 100644 --- a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Dutch spelling of numbers is not really officially regulated. diff --git a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs index 15bd23588..4068c2bc3 100644 --- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { class EnglishNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs index c39b2dfbe..1e2d0f081 100644 --- a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class FarsiNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs index 6f276fd41..ebff81760 100644 --- a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class FinnishNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs index 16de2d7f9..a211e3a23 100644 --- a/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class FrenchBelgianNumberToWordsConverter : FrenchNumberToWordsConverterBase { diff --git a/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs index a37050ace..8048d9663 100644 --- a/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class IcelandicNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs index d8c1a9b84..acfb0304d 100644 --- a/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class LithuanianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs index 78d97776d..b929f8103 100644 --- a/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer; +namespace Humanizer; class LuxembourgishNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs index 4afdfb296..ffe021da4 100644 --- a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs +++ b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class MalteseNumberToWordsConvertor : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs index 802acdb30..3fdbe6e98 100644 --- a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class PolishNumberToWordsConverter(CultureInfo? culture) : GenderedNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs index 2f963dc33..56382d1be 100644 --- a/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class PortugueseNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs index 8c4770eb3..b8ef26687 100644 --- a/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class RomanianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs index 528e5427e..a9cbd1107 100644 --- a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class RussianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs index b5b75a8b4..b1f19e42b 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class SerbianCyrlNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs index c5143c144..c8003d0bb 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class SerbianNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs index 1f7b0b843..b94b233d7 100644 --- a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class SlovenianNumberToWordsConverter(CultureInfo? culture) : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs index b9427e081..c570f95f6 100644 --- a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class SpanishNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs index 896d40b2e..2dc1f2815 100644 --- a/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class SwedishNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs index 6e4ee2980..2e9a66104 100644 --- a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Humanizer +namespace Humanizer { class TamilNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs index e64fbd52e..553913d3d 100644 --- a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class TurkishNumberToWordConverter : GenderlessNumberToWordsConverter diff --git a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs index bdb17fa1b..c46056317 100644 --- a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class UkrainianNumberToWordsConverter : GenderedNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs index fe7322726..1a1a070cd 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class UzbekCyrlNumberToWordConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs index 37d02765a..6df6dbdcb 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class UzbekLatnNumberToWordConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs index a946cc04c..49861987c 100644 --- a/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class VietnameseNumberToWordsConverter : GenderlessNumberToWordsConverter { diff --git a/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs index 090c17a9c..279389f72 100644 --- a/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/ArmenianOrdinalizer.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class ArmenianOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs index 6f8c926f0..49a7aa323 100644 --- a/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/AzerbaijaniOrdinalizer.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class AzerbaijaniOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs index d7b4ff52a..348a37d70 100644 --- a/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/DefaultOrdinalizer.cs @@ -1,6 +1,4 @@ - -#nullable enable -namespace Humanizer +namespace Humanizer { class DefaultOrdinalizer : IOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs index 9f6ebdbfe..295b5fa5e 100644 --- a/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/FrenchOrdinalizer.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class FrenchOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs index 0ba117bd7..2d7148cac 100644 --- a/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// The interface used to localise the Ordinalize method diff --git a/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs index dbb30ba90..fe2f8c01c 100644 --- a/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs @@ -1,6 +1,4 @@ - -#nullable enable -namespace Humanizer +namespace Humanizer { class RomanianOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs index b091ce23c..48fba9c3f 100644 --- a/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class SpanishOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs index ca9f19d34..cd01189bc 100644 --- a/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class UkrainianOrdinalizer : DefaultOrdinalizer { diff --git a/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs b/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs index 0582893d4..648591a9a 100644 --- a/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs +++ b/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer; +namespace Humanizer; public partial class ResourceKeys { diff --git a/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs b/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs index 3385bbefc..f7aa2a3f6 100644 --- a/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs +++ b/src/Humanizer/Localisation/ResourceKeys.TimeUnitSymbol.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer; +namespace Humanizer; public partial class ResourceKeys { diff --git a/src/Humanizer/Localisation/Tense.cs b/src/Humanizer/Localisation/Tense.cs index 5bcecf015..e81c9e14c 100644 --- a/src/Humanizer/Localisation/Tense.cs +++ b/src/Humanizer/Localisation/Tense.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Enumerates the possible time references; past or future. diff --git a/src/Humanizer/Localisation/TimeUnit.cs b/src/Humanizer/Localisation/TimeUnit.cs index 0a6d90daf..bede6631f 100644 --- a/src/Humanizer/Localisation/TimeUnit.cs +++ b/src/Humanizer/Localisation/TimeUnit.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { public enum TimeUnit { diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index 368590281..b561d353c 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Transform a number into words; e.g. 1 => one diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index a2ddc41ad..bf8807bc1 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Humanizes TimeSpan into human readable form diff --git a/src/Humanizer/TimeUnitToSymbolExtensions.cs b/src/Humanizer/TimeUnitToSymbolExtensions.cs index ded387d92..6657436cf 100644 --- a/src/Humanizer/TimeUnitToSymbolExtensions.cs +++ b/src/Humanizer/TimeUnitToSymbolExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Transform a time unit into a symbol; e.g. => "a" diff --git a/src/Humanizer/ToQuantityExtensions.cs b/src/Humanizer/ToQuantityExtensions.cs index d334be60d..14637b484 100644 --- a/src/Humanizer/ToQuantityExtensions.cs +++ b/src/Humanizer/ToQuantityExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Enumerates the ways of displaying a quantity value when converting diff --git a/src/Humanizer/Transformer/ICulturedStringTransformer.cs b/src/Humanizer/Transformer/ICulturedStringTransformer.cs index 538283947..acfeba711 100644 --- a/src/Humanizer/Transformer/ICulturedStringTransformer.cs +++ b/src/Humanizer/Transformer/ICulturedStringTransformer.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { /// /// Can transform a string with the given culture diff --git a/src/Humanizer/Transformer/IStringTransformer.cs b/src/Humanizer/Transformer/IStringTransformer.cs index b97b73106..cbb893463 100644 --- a/src/Humanizer/Transformer/IStringTransformer.cs +++ b/src/Humanizer/Transformer/IStringTransformer.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Humanizer { /// diff --git a/src/Humanizer/Transformer/ToLowerCase.cs b/src/Humanizer/Transformer/ToLowerCase.cs index 90899375a..81c99766c 100644 --- a/src/Humanizer/Transformer/ToLowerCase.cs +++ b/src/Humanizer/Transformer/ToLowerCase.cs @@ -1,4 +1,3 @@ -#nullable enable namespace Humanizer { class ToLowerCase : ICulturedStringTransformer diff --git a/src/Humanizer/Transformer/ToSentenceCase.cs b/src/Humanizer/Transformer/ToSentenceCase.cs index 923a8e918..3376edece 100644 --- a/src/Humanizer/Transformer/ToSentenceCase.cs +++ b/src/Humanizer/Transformer/ToSentenceCase.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class ToSentenceCase : ICulturedStringTransformer { diff --git a/src/Humanizer/Transformer/ToTitleCase.cs b/src/Humanizer/Transformer/ToTitleCase.cs index fc6fdc529..a03af4eea 100644 --- a/src/Humanizer/Transformer/ToTitleCase.cs +++ b/src/Humanizer/Transformer/ToTitleCase.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class ToTitleCase : ICulturedStringTransformer { diff --git a/src/Humanizer/Transformer/ToUpperCase.cs b/src/Humanizer/Transformer/ToUpperCase.cs index 7c9276112..67246a9de 100644 --- a/src/Humanizer/Transformer/ToUpperCase.cs +++ b/src/Humanizer/Transformer/ToUpperCase.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace Humanizer +namespace Humanizer { class ToUpperCase : ICulturedStringTransformer { From b87e36faa1a6cf04e894235ae959e2b56576eab5 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:57:29 +1100 Subject: [PATCH 37/39] Update HeadingExtensions.cs --- src/Humanizer/HeadingExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Humanizer/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs index 5b863653d..ef1c460fd 100644 --- a/src/Humanizer/HeadingExtensions.cs +++ b/src/Humanizer/HeadingExtensions.cs @@ -35,7 +35,7 @@ public static class HeadingExtensions /// The heading value /// Whether to return a short result or not. /// The culture to return the textual representation in - public static string? ToHeading(this double heading, HeadingStyle style = HeadingStyle.Abbreviated, CultureInfo? culture = null) + public static string ToHeading(this double heading, HeadingStyle style = HeadingStyle.Abbreviated, CultureInfo? culture = null) { var val = (int)(heading / 22.5 + .5); From ee7d4f32ad395b19d5ce94b155ca3cdf93a2773a Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Feb 2024 23:59:09 +1100 Subject: [PATCH 38/39] . --- src/Humanizer/Truncation/FixedLengthTruncator.cs | 1 + src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Humanizer/Truncation/FixedLengthTruncator.cs b/src/Humanizer/Truncation/FixedLengthTruncator.cs index 79d6efb2a..eaf20f84a 100644 --- a/src/Humanizer/Truncation/FixedLengthTruncator.cs +++ b/src/Humanizer/Truncation/FixedLengthTruncator.cs @@ -5,6 +5,7 @@ /// class FixedLengthTruncator : ITruncator { + [return: NotNullIfNotNull(nameof(value))] public string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) { if (value == null) diff --git a/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs index d5c70a71f..dd4a9adfc 100644 --- a/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs +++ b/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs @@ -5,6 +5,7 @@ namespace Humanizer /// class FixedNumberOfCharactersTruncator : ITruncator { + [return: NotNullIfNotNull(nameof(value))] public string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right) { if (value == null) From 02a964b58bcf74c3c758d022ff9c5ee7c863a827 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 23 Feb 2024 10:41:31 +1100 Subject: [PATCH 39/39] . --- ...licApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt | 2 +- ...PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt index f0ed3bf0c..0e0d8b1ca 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt @@ -281,7 +281,7 @@ namespace Humanizer public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo? culture = null) { } public static double FromHeadingArrow(this char heading) { } public static double FromHeadingArrow(this string heading) { } - public static string? ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo? culture = null) { } + public static string ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo? culture = null) { } public static char ToHeadingArrow(this double heading) { } } public enum HeadingStyle diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt index 9ee2eb303..8c668de6f 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt @@ -261,7 +261,7 @@ namespace Humanizer public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo? culture = null) { } public static double FromHeadingArrow(this char heading) { } public static double FromHeadingArrow(this string heading) { } - public static string? ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo? culture = null) { } + public static string ToHeading(this double heading, Humanizer.HeadingStyle style = 0, System.Globalization.CultureInfo? culture = null) { } public static char ToHeadingArrow(this double heading) { } } public enum HeadingStyle