Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace App
- {
- public class World
- {
- private readonly Dictionary<Type, object> Resources = new Dictionary<Type, object>();
- public void Insert<T>(T resource)
- where T : class
- {
- Resources.Add(typeof(T), resource);
- }
- public T Fetch<T>()
- where T : class
- {
- if (Resources.TryGetValue(typeof(T), out var resource))
- return (T) resource;
- return null;
- }
- public bool Contains<T>()
- where T : class
- {
- return Resources.ContainsKey(typeof(T));
- }
- }
- public static class WorldVal
- {
- private class ValueWrapper<T>
- {
- public T Val;
- }
- public static T Fetch<T>(this World world)
- where T : struct
- {
- return world.Fetch<ValueWrapper<T>>().Val;
- }
- public static void Insert<T>(this World world, T resource)
- where T : struct
- {
- world.Insert(new ValueWrapper<T> {Val = resource});
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement