using System.Collections.Generic; namespace gaemstone.Utility; public static class CallbackContextHelper { private static readonly Dictionary _contexts = new(); private static nint _counter = 0; public static nint Create(T context) where T : notnull { lock (_contexts) { var id = _counter++; _contexts.Add(id, context); return id; } } public static T Get(nint id) { lock (_contexts) return (T)_contexts[id]; } public static void Free(nint id) { lock (_contexts) _contexts.Remove(id); } }