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.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/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.Tests.Shared/CollectionHumanizeTests.cs b/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs
index 8fa0ab3ad..51a12e29d 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,15 +97,15 @@ 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() =>
- 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/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/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.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/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt
index 7b867eab4..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
@@ -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(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) { }
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) { }
@@ -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) { }
@@ -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
{
@@ -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) { }
@@ -772,11 +774,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 +888,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 +1797,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 +1841,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 +1875,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 +1892,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
{
@@ -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 946bb63d7..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
@@ -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(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) { }
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) { }
@@ -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) { }
@@ -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
{
@@ -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) { }
@@ -556,11 +558,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 +672,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 +1151,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 +1185,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 +1215,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 +1232,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
{
@@ -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/Bytes/ByteRate.cs b/src/Humanizer/Bytes/ByteRate.cs
index 1b26dc5aa..62035ec00 100644
--- a/src/Humanizer/Bytes/ByteRate.cs
+++ b/src/Humanizer/Bytes/ByteRate.cs
@@ -37,7 +37,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 9eff18f9e..9cb75024e 100644
--- a/src/Humanizer/Bytes/ByteSize.cs
+++ b/src/Humanizer/Bytes/ByteSize.cs
@@ -62,7 +62,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);
@@ -97,7 +97,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);
@@ -193,20 +193,20 @@ public static ByteSize FromTerabytes(double value) =>
public override string ToString() =>
ToString(NumberFormatInfo.CurrentInfo);
- public string ToString(IFormatProvider provider)
+ public string ToString(IFormatProvider? provider)
{
provider ??= CultureInfo.CurrentCulture;
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) =>
+ 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)
{
format ??= "G";
provider ??= CultureInfo.CurrentCulture;
@@ -280,10 +280,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)
{
@@ -309,7 +309,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)
{
@@ -384,10 +384,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))
@@ -412,7 +412,7 @@ public static bool TryParse(string s, IFormatProvider formatProvider, out ByteSi
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;
@@ -486,7 +486,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;
@@ -499,7 +499,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/Bytes/ByteSizeExtensions.cs b/src/Humanizer/Bytes/ByteSizeExtensions.cs
index ba3c5f292..8db587650 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);
///
@@ -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/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs
index 0d9279e7c..db8ef4571 100644
--- a/src/Humanizer/Configuration/Configurator.cs
+++ b/src/Humanizer/Configuration/Configurator.cs
@@ -48,14 +48,14 @@ 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);
///
/// 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/Configuration/LocaliserRegistry.cs b/src/Humanizer/Configuration/LocaliserRegistry.cs
index e5fd6f817..6efc8141d 100644
--- a/src/Humanizer/Configuration/LocaliserRegistry.cs
+++ b/src/Humanizer/Configuration/LocaliserRegistry.cs
@@ -6,8 +6,8 @@
public class LocaliserRegistry
where TLocaliser : class
{
- readonly IDictionary> _localisers = new Dictionary>();
- readonly Func _defaultLocaliser;
+ readonly Dictionary> _localisers = new();
+ readonly Func _defaultLocaliser;
///
/// Creates a localiser registry with the default localiser set to the provided value
@@ -18,7 +18,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;
///
@@ -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);
///
@@ -43,14 +43,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)
+ 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/DateHumanizeExtensions.cs b/src/Humanizer/DateHumanizeExtensions.cs
index b4d6f098b..89708f195 100644
--- a/src/Humanizer/DateHumanizeExtensions.cs
+++ b/src/Humanizer/DateHumanizeExtensions.cs
@@ -13,7 +13,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 +30,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 +47,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 +61,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 +79,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 +92,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 +110,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 +125,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/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs
index 959db0c01..b61eedf33 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs
@@ -8,7 +8,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;
@@ -20,7 +20,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);
@@ -32,7 +32,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;
@@ -40,7 +40,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;
@@ -131,7 +131,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));
@@ -147,7 +147,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);
@@ -163,7 +163,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));
@@ -172,7 +172,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/DefaultDateOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs
index e868c3519..3f941ecb0 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateOnlyHumanizeStrategy.cs
@@ -10,7 +10,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/DefaultDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs
index 46fa830ff..dc96c1ed6 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs
@@ -8,7 +8,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 16ef0861e..96f178b9d 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs
@@ -8,7 +8,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/DefaultTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs
index 85f839961..ab180a38a 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/DefaultTimeOnlyHumanizeStrategy.cs
@@ -10,7 +10,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 ce9c3d841..306e4affb 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateOnlyHumanizeStrategy.cs
@@ -10,7 +10,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/IDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs
index 272236759..f5bd2a933 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs
@@ -8,6 +8,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 28eae6aef..5c13a28b4 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs
@@ -8,6 +8,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/ITimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs
index 01659062a..af44db8c3 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/ITimeOnlyHumanizeStrategy.cs
@@ -10,7 +10,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 75792576e..aa543db1d 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateOnlyHumanizeStrategy.cs
@@ -19,7 +19,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/PrecisionDateTimeHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs
index d35209583..653a06d62 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs
@@ -17,7 +17,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/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs
index 8df72d2f8..220ee6857 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs
@@ -17,7 +17,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/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs
index 4b86f4001..6f1c19261 100644
--- a/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs
+++ b/src/Humanizer/DateTimeHumanizeStrategy/PrecisionTimeOnlyHumanizeStrategy.cs
@@ -19,7 +19,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/EnumCache.cs b/src/Humanizer/EnumCache.cs
index de3ed1420..8ebd728b6 100644
--- a/src/Humanizer/EnumCache.cs
+++ b/src/Humanizer/EnumCache.cs
@@ -62,14 +62,14 @@ 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)
{
description = displayAttribute.GetDescription() ?? displayAttribute.GetName();
- return true;
+ return description != null;
}
foreach (var attr in member.GetCustomAttributes())
diff --git a/src/Humanizer/EnumDehumanizeExtensions.cs b/src/Humanizer/EnumDehumanizeExtensions.cs
index 617ac998b..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!
@@ -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/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs
index 623a9d1dd..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);
@@ -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/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs
index d80d7e6de..392f96eea 100644
--- a/src/Humanizer/Inflections/Vocabulary.cs
+++ b/src/Humanizer/Inflections/Vocabulary.cs
@@ -66,8 +66,14 @@ 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)
{
+ if (word == null)
+ {
+ return null;
+ }
+
var s = LetterS(word);
if (s != null)
{
@@ -92,7 +98,7 @@ public string Pluralize(string word, bool inputIsKnownToBeSingular = true)
return word;
}
- return result;
+ return result!;
}
///
@@ -101,8 +107,13 @@ public string Pluralize(string word, bool inputIsKnownToBeSingular = true)
/// 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)
{
@@ -134,7 +145,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 +190,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 +200,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))
{
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/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs b/src/Humanizer/Localisation/CollectionFormatters/DefaultCollectionFormatter.cs
index cc9b227d4..78bae6ee2 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)
{
@@ -53,7 +53,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/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);
diff --git a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs
index c3eac4bae..94c0198c1 100644
--- a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs
@@ -152,7 +152,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/ArmenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs
index 9358718ad..a0b405732 100644
--- a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs
@@ -169,7 +169,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/BanglaNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs
index d04cea715..1df5580ef 100644
--- a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs
@@ -110,7 +110,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/CroatianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs
index f71dbda71..9c5bbde40 100644
--- a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs
@@ -1,6 +1,6 @@
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 3e7e3471b..ab39ab84f 100644
--- a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs
@@ -1,6 +1,6 @@
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 fec946b60..f5619c34d 100644
--- a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs
@@ -2,13 +2,13 @@
{
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/DutchNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs
index 86d72d1ea..8a3f7f515 100644
--- a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs
@@ -15,9 +15,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/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs
index c05be0c7d..4068c2bc3 100644
--- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs
@@ -149,7 +149,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/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/IcelandicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs
index f55190098..8048d9663 100644
--- a/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs
@@ -14,9 +14,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 +29,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 +54,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 +120,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 +137,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 +164,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 +177,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 +218,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 +261,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 +292,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);
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);
}
}
diff --git a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs
index 96961fff0..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
@@ -57,9 +60,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/NorwegianBokmalNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs
index 47e71e729..ab333fc2d 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)
diff --git a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs
index 7e3f2f34f..3fdbe6e98 100644
--- a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs
@@ -1,6 +1,6 @@
namespace Humanizer
{
- class PolishNumberToWordsConverter(CultureInfo culture) :
+ class PolishNumberToWordsConverter(CultureInfo? culture) :
GenderedNumberToWordsConverter
{
static readonly string[] HundredsMap =
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)
{
diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs
index 196cada14..b1f19e42b 100644
--- a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs
@@ -1,6 +1,6 @@
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 71cf0be3f..c8003d0bb 100644
--- a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs
@@ -1,6 +1,6 @@
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 4e9ef1f24..b94b233d7 100644
--- a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs
@@ -1,6 +1,6 @@
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/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs
index 2f66bd0f2..2dc1f2815 100644
--- a/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs
@@ -8,9 +8,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 20c853b3f..aef5d920e 100644
--- a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs
+++ b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs
@@ -266,7 +266,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/Resources.cs b/src/Humanizer/Localisation/Resources.cs
index 0eb9dcbf3..765849689 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);
@@ -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/MetricNumeralExtensions.cs b/src/Humanizer/MetricNumeralExtensions.cs
index a0ffbf1b0..847d39de9 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/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..bf8807bc1 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,21 +52,19 @@ 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);
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;
- var timeParts = new List();
+ var timeParts = new List();
foreach (var timeUnit in _timeUnits)
{
@@ -87,7 +85,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)
{
@@ -177,19 +175,19 @@ 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)
: null;
- static List CreateTimePartsWithNoTimeValue(string noTimeValue) =>
+ 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)
+ static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, int precision, bool countEmptyUnits)
{
if (!countEmptyUnits)
{
@@ -205,7 +203,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)
{
diff --git a/src/Humanizer/TimeUnitToSymbolExtensions.cs b/src/Humanizer/TimeUnitToSymbolExtensions.cs
index 3f0de114b..6657436cf 100644
--- a/src/Humanizer/TimeUnitToSymbolExtensions.cs
+++ b/src/Humanizer/TimeUnitToSymbolExtensions.cs
@@ -10,7 +10,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);
}
}
diff --git a/src/Humanizer/ToQuantityExtensions.cs b/src/Humanizer/ToQuantityExtensions.cs
index 96424c11e..14637b484 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/Transformer/ToLowerCase.cs b/src/Humanizer/Transformer/ToLowerCase.cs
index 9f6f38a23..81c99766c 100644
--- a/src/Humanizer/Transformer/ToLowerCase.cs
+++ b/src/Humanizer/Transformer/ToLowerCase.cs
@@ -5,7 +5,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..3376edece 100644
--- a/src/Humanizer/Transformer/ToSentenceCase.cs
+++ b/src/Humanizer/Transformer/ToSentenceCase.cs
@@ -5,7 +5,7 @@ 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..a03af4eea 100644
--- a/src/Humanizer/Transformer/ToTitleCase.cs
+++ b/src/Humanizer/Transformer/ToTitleCase.cs
@@ -5,7 +5,7 @@ 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..67246a9de 100644
--- a/src/Humanizer/Transformer/ToUpperCase.cs
+++ b/src/Humanizer/Transformer/ToUpperCase.cs
@@ -5,7 +5,7 @@ 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;
diff --git a/src/Humanizer/TruncateExtensions.cs b/src/Humanizer/TruncateExtensions.cs
index 6149cbf9e..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);
///
@@ -22,7 +23,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 +35,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);
///
@@ -45,7 +48,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/FixedLengthTruncator.cs b/src/Humanizer/Truncation/FixedLengthTruncator.cs
index 81f09b619..eaf20f84a 100644
--- a/src/Humanizer/Truncation/FixedLengthTruncator.cs
+++ b/src/Humanizer/Truncation/FixedLengthTruncator.cs
@@ -5,7 +5,8 @@
///
class FixedLengthTruncator : 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)
{
diff --git a/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs
index 7c5233190..b353664c6 100644
--- a/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs
+++ b/src/Humanizer/Truncation/FixedNumberOfCharactersTruncator.cs
@@ -5,7 +5,8 @@ namespace Humanizer
///
class FixedNumberOfCharactersTruncator : 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)
{
diff --git a/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs b/src/Humanizer/Truncation/FixedNumberOfWordsTruncator.cs
index 4271b636c..d32e012ae 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)
{
@@ -17,7 +18,7 @@ public string Truncate(string value, int length, string truncationString, Trunca
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;
@@ -28,7 +29,7 @@ public string Truncate(string value, int length, string truncationString, Trunca
: 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;
@@ -56,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;
diff --git a/src/Humanizer/Truncation/ITruncator.cs b/src/Humanizer/Truncation/ITruncator.cs
index 9032613b0..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
- string Truncate(string value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right);
+ [return: NotNullIfNotNull(nameof(value))]
+ string? Truncate(string? value, int length, string? truncationString, TruncateFrom truncateFrom = TruncateFrom.Right);
}
}