using System; public static class EventManager { public interface Event { } private class EventTypeManager where T : Event { public static OnEvent handler; } public delegate void OnEvent(T data) where T : Event; public static void Send(T data) where T : Event { OnEvent handler = EventTypeManager.handler; if (handler != null) { handler(data); } } public static void Connect(OnEvent handler) where T : Event { EventTypeManager.handler = (OnEvent)Delegate.Combine(EventTypeManager.handler, handler); } public static void Disconnect(OnEvent handler) where T : Event { EventTypeManager.handler = (OnEvent)Delegate.Remove(EventTypeManager.handler, handler); } }