public IDictionary <string, CommandActionRoute> GetCommandAttributeRoutes(ChromelyController controller) { if (controller == null) { return(null); } var result = new Dictionary <string, CommandActionRoute>(); var methodInfos = controller.GetType().GetMethods() .Where(m => m.GetCustomAttributes(typeof(CommandActionAttribute), false).Length > 0) .ToArray(); foreach (var item in methodInfos) { var customAttributeDelegate = CreateDelegate(controller, item) as Action <IDictionary <string, string> >; var attribute = item.GetCustomAttribute <CommandActionAttribute>(); if (customAttributeDelegate != null && attribute != null) { var key = RouteKey.CreateCommandKey(attribute.RouteKey); var commandRoute = new CommandActionRoute(attribute.RouteKey, customAttributeDelegate, attribute.Description); result[key] = commandRoute; } } return(result); }
protected void RegisterCommand(string path, Action <IDictionary <string, string> > action, string description = null) { if (string.IsNullOrWhiteSpace(path) || action == null) { return; } var commandKey = RouteKey.CreateCommandKey(path); var command = new CommandActionRoute(path, action, description); CommandRouteDictionary[commandKey] = command; }