using System; using System.Collections.Generic; public struct CustomUnRegister : IUnRegister { private Action mOnUnRegister { get; set; } public CustomUnRegister(Action onUnRegister) => mOnUnRegister = onUnRegister; public void UnRegister() { mOnUnRegister.Invoke(); mOnUnRegister = null; } } public interface IUnRegister { void UnRegister(); } public interface IUnRegisterList { List UnregisterList { get; } } public interface IEasyEvent { IUnRegister Register(Action onEvent); } public class EasyEvent : IEasyEvent { private Action mOnEvent = () => { }; public IUnRegister Register(Action onEvent) { mOnEvent += onEvent; return new CustomUnRegister(() => { UnRegister(onEvent); }); } public void UnRegister(Action onEvent) => mOnEvent -= onEvent; public void Trigger() => mOnEvent?.Invoke(); } public class EasyEvent : IEasyEvent { private Action mOnEvent = e => { }; public IUnRegister Register(Action onEvent) { mOnEvent -= onEvent; mOnEvent += onEvent; return new CustomUnRegister(() => { UnRegister(onEvent); }); } public void UnRegister(Action onEvent) => mOnEvent -= onEvent; public void Trigger(T t) => mOnEvent?.Invoke(t); public void Close() => mOnEvent = null; IUnRegister IEasyEvent.Register(Action onEvent) { return Register(Action); void Action(T _) => onEvent(); } } public class EasyEvent : IEasyEvent { private Action mOnEvent = (t, k) => { }; public IUnRegister Register(Action onEvent) { mOnEvent += onEvent; return new CustomUnRegister(() => { UnRegister(onEvent); }); } public void UnRegister(Action onEvent) => mOnEvent -= onEvent; public void Trigger(T t, K k) => mOnEvent?.Invoke(t, k); IUnRegister IEasyEvent.Register(Action onEvent) { return Register(Action); void Action(T _, K __) => onEvent(); } } public class EasyEvent : IEasyEvent { private Action mOnEvent = (t, k, s) => { }; public IUnRegister Register(Action onEvent) { mOnEvent += onEvent; return new CustomUnRegister(() => { UnRegister(onEvent); }); } public void UnRegister(Action onEvent) => mOnEvent -= onEvent; public void Trigger(T t, K k, S s) => mOnEvent?.Invoke(t, k, s); IUnRegister IEasyEvent.Register(Action onEvent) { return Register(Action); void Action(T _, K __, S ___) => onEvent(); } }