From 94a841b2fc37c76d8f3f39bca4f735961b4beb9c Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 22 Dec 2022 12:28:35 +0000 Subject: [PATCH] Allow null input in TimeSpanParser.TryParse --- CHANGELOG.md | 1 + X10D/src/Time/TimeSpanParser.cs | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d259b43..7b18482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ - X10D.Unity: Added `WaitForTimeSpanRealtimeNoAlloc` yield instruction ### Changed +- X10D: `TimeSpanParser.TryParse` now accepts a nullable string, and returns false if this input is null or empty - X10D.Unity: Obsolesced `Singleton` ## [3.1.0] diff --git a/X10D/src/Time/TimeSpanParser.cs b/X10D/src/Time/TimeSpanParser.cs index 2839f22..a6078ee 100644 --- a/X10D/src/Time/TimeSpanParser.cs +++ b/X10D/src/Time/TimeSpanParser.cs @@ -1,4 +1,6 @@ -namespace X10D.Time; +using System.Diagnostics.CodeAnalysis; + +namespace X10D.Time; /// /// Represents a class which contains a parser which converts into . @@ -54,15 +56,15 @@ public static class TimeSpanParser /// /// When this method returns, contains the parsed result. /// if the parse was successful, otherwise. - /// is . - public static bool TryParse(string value, out TimeSpan result) + public static bool TryParse([NotNullWhen(true)] string? value, out TimeSpan result) { - if (value is null) + result = TimeSpan.Zero; + + if (string.IsNullOrWhiteSpace(value)) { - throw new ArgumentNullException(nameof(value)); + return false; } - result = TimeSpan.Zero; var unitValue = 0; for (var index = 0; index < value.Length; index++)