private void AddEventHandlers(IMainMenuInstance mainMenu) { var handlerMethods = ClassHelper.FindAnnotatedMethods <MenuEventHandlerAttribute>(mainMenu); foreach (var method in handlerMethods) { var attribute = method.GetAttribute <MenuEventHandlerAttribute>(); try { if (attribute.Before) { before.Add(attribute.MenuId, method.CreateBeforeEventDelegate <MenuEvent>(mainMenu)); } else { after.Add(attribute.MenuId, method.CreateAfterEventDelegate <MenuEvent>(mainMenu)); } } catch (ArgumentException e) { var exception = new EventHandlerAlreadyExistsException( $"A menu event handler for {attribute.MenuId} already exists. Duplicate method {method.Name}.", e); throw exception; } HandlerAdded(this, new HandlerAddedEventArgs(BoEventTypes.et_MENU_CLICK, @"ALL_FORMS")); } }
/// <summary> /// Initializes a new instance of the <see cref="EventHandlerAlreadyExistsException" /> class. /// </summary> /// <param name="key">The key of the event handler.</param> public static EventHandlerAlreadyExistsException CreateFromKey(string key) { var exception = new EventHandlerAlreadyExistsException($"{key} is already registered."); return(exception); }