public static void UnRegisterEvent(object listener) { Type type = listener.GetType(); MethodInfo[] methodInfos = type.GetMethods(); foreach (MethodInfo methodInfo in methodInfos) { EventAttr eventAttr = (EventAttr)methodInfo.GetCustomAttribute(typeof(EventAttr), false); if (eventAttr == null) { continue; } UnRegisterEvent(eventAttr.EventType, methodInfo, listener); } }
public static void RegisterEvent(object listener) { Type type = listener.GetType(); MethodInfo[] methodInfos = type.GetMethods(); foreach (MethodInfo methodInfo in methodInfos) { EventAttr eventAttr = (EventAttr)methodInfo.GetCustomAttribute(typeof(EventAttr), false); if (eventAttr != null) { string eventType = eventAttr.EventType; if (string.IsNullOrEmpty(eventType)) { eventType = methodInfo.Name; } RegisterEvent(eventType, methodInfo, listener); } } }