Skip to content

Commit

Permalink
Allow null input in TimeSpanParser.TryParse
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Dec 22, 2022
1 parent fdc9e64 commit 94a841b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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<T>`

## [3.1.0]
Expand Down
14 changes: 8 additions & 6 deletions X10D/src/Time/TimeSpanParser.cs
@@ -1,4 +1,6 @@
namespace X10D.Time;
using System.Diagnostics.CodeAnalysis;

namespace X10D.Time;

/// <summary>
/// Represents a class which contains a <see cref="string" /> parser which converts into <see cref="TimeSpan" />.
Expand Down Expand Up @@ -54,15 +56,15 @@ public static class TimeSpanParser
/// </param>
/// <param name="result">When this method returns, contains the parsed result.</param>
/// <returns><see langword="true" /> if the parse was successful, <see langword="false" /> otherwise.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
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++)
Expand Down

0 comments on commit 94a841b

Please sign in to comment.