using System; namespace BizHawk.Client.Common { public sealed class UserDataApi : IUserData { /// (from setter) type of cannot be used in userdata public object this[string key] { get => Global.UserBag.TryGetValue(key, out var value) ? value : null; set { if (value != null) { var t = value.GetType(); if (!t.IsPrimitive && t != typeof(string)) throw new InvalidOperationException("Invalid type for userdata"); } Global.UserBag[key] = value; } } public void Clear() => Global.UserBag.Clear(); public bool ContainsKey(string key) => Global.UserBag.ContainsKey(key); public bool Remove(string key) => Global.UserBag.Remove(key); } }