Utils/CollectionExtensions.cs

Extension method for NetDictionary that returns the value for a key or a provided default when the key is missing. It calls TryGetValue and returns either the found value or the defaultValue.


namespace KOTH;

public static class CollectionExtensions
{
	public static TValue GetValueOrDefault<TKey, TValue>(this NetDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default)
	{
		return dict.TryGetValue(key, out var value) ? value : defaultValue;
	}
}