Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
        }