public static void RunMenu(Type menuHolderType) { var menu = new ConzapMenu(); var instance = Activator.CreateInstance(menuHolderType); var menuItemAttributedMethods = menuHolderType.GetMethods(). Where(m => m.GetCustomAttributes(typeof(ConzapMenuItemAttribute), true).Count() > 0); foreach (var menuItemMethod in menuItemAttributedMethods) { ConzapMenuItemAttribute metaData = menuItemMethod.GetCustomAttributes(typeof(ConzapMenuItemAttribute), true)[0] as ConzapMenuItemAttribute; var index = metaData.Index; var header = metaData.Header; var delegateAction = (Action)menuItemMethod.CreateDelegate(typeof(Action), instance); menu.Add(header, delegateAction); } menu.Run(); }
public static void RunMenu(params ConzapMenuItem[] menuItems) { var menu = new ConzapMenu(menuItems.ToList()); menu.Run(); }