Beispiel #1
0
        public virtual void Register(string uri, ControllerMapping controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            _controllers.Add(controller.Uri.ToLower(), controller);
        }
Beispiel #2
0
        public virtual bool TryMapping(string uri, out ControllerMapping mapping)
        {
            mapping = null;
            if (_controllers.Contains(uri))
            {
                mapping = (ControllerMapping)_controllers[uri];
                return(true);
            }

            return(false);
        }
        private void MapController(Type type)
        {
            ControllerMapping mapping = new ControllerMapping(type)
            {
                Uri = type.Name.Replace("Controller", string.Empty)
            };

            foreach (MethodInfo method in type.GetMethods())
            {
                if (type.IsAbstract || type.IsNotPublic)
                {
                    continue;
                }

                if (method.ReturnType.Equals(typeof(IActionResult)))
                {
                    mapping.Add(method);
                }
            }
            _controllers.Add(mapping);
        }