Fixes for unit tests

This commit is contained in:
2025-06-07 11:34:37 +02:00
parent 273d26057a
commit af0126e413
5 changed files with 26 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;
namespace PkmnLib.Static.Utils;
/// <summary>
@@ -26,8 +28,18 @@ public readonly record struct StringKey
/// <summary>
/// Converts a <see cref="string"/> to a <see cref="StringKey"/>.
/// </summary>
[return: NotNullIfNotNull("key")]
public static implicit operator StringKey?(string? key) =>
string.IsNullOrWhiteSpace(key) ? null! : new StringKey(key);
/// <summary>
/// Converts a <see cref="string"/> to a <see cref="StringKey"/>.
/// Throws an <see cref="ArgumentException"/> if the key is null or whitespace.
/// </summary>
public static implicit operator StringKey(string key) =>
string.IsNullOrWhiteSpace(key) ? default : new StringKey(key);
string.IsNullOrWhiteSpace(key)
? throw new ArgumentException("Key cannot be null or whitespace.", nameof(key))
: new StringKey(key);
/// <inheritdoc cref="string.ToString()"/>
public override string ToString() => _key.ToLowerInvariant();