I am introducing a menu system that uses a composite design pattern. I have the following MenuElement interface:
public interface MenuElement
{
void AddMenuElement( MenuElement menuToAdd );
void RemoveMenuElement( MenuElement menuToRemove );
MenuElement GetMenuElement( int index );
void Activate();
}
I was thinking of turning on the "OnActivate" event in this interface, so that MenuItems that implement this interface can trigger functions when activated. I tried to implement it as follows:
public interface MenuElement
{
public delegate void MenuEvent();
event MenuEvent onActivate;
void AddMenuElement( MenuElement menuToAdd );
void RemoveMenuElement( MenuElement menuToRemove );
MenuElement GetMenuElement( int index );
void Activate();
}
However, the compiler will not let me declare a delegate inside the interface. I know the type of C # event called EventHandler, but unlike my desired MenuEvent, it requires both objects and EventArgs parameters. I also considered moving my event and delegation to MenuItem, but I'm still wondering if it is possible for the interface to include a custom event.
? # EventHandler ?