namespace PkmnLib.Static.Utils; /// /// A case-insensitive string key. We use this class for things like looking up data from dictionaries, etc. /// /// /// This is a struct, as it's effectively just a wrapper around a single reference object. Heap allocation would be silly. /// public readonly record struct StringKey { private readonly string _key; /// public StringKey(string key) { if (string.IsNullOrWhiteSpace(key)) throw new ArgumentException("Key cannot be null or whitespace.", nameof(key)); _key = key; } /// /// Converts a to a . /// public static implicit operator string(StringKey key) => key._key; /// /// Converts a to a . /// public static implicit operator StringKey(string key) => string.IsNullOrWhiteSpace(key) ? default : new StringKey(key); /// public override string ToString() => _key.ToLowerInvariant(); /// public bool Equals(StringKey other) => string.Equals(_key, other._key, StringComparison.InvariantCultureIgnoreCase); /// public override int GetHashCode() => StringComparer.InvariantCultureIgnoreCase.GetHashCode(_key); }