qamp/Qrakhen.Qamp.Core/Collections/Register.cs

26 lines
618 B
C#

namespace Qrakhen.Qamp.Core.Collections;
public class Register<TKey, TValue> :
IGetSet<TKey, TValue>
where TKey : notnull
{
private readonly Dictionary<TKey, TValue> _data = new();
public int Length => _data.Count;
public TValue this[TKey key] {
get => Get(key);
set => Set(key, value);
}
public TKey Add(TKey key, TValue value)
{
_data.Add(key, value);
return key;
}
public TValue Get(TKey key) => _data[key];
public void Set(TKey key, TValue value) => _data[key] = value;
public bool Has(TKey key) => _data.ContainsKey(key);
}