Ejemplo n.º 1
0
        private MvcActionFunction RegisterActionFunction(Type controllerType, string actionName, bool handlePathInfo, C1FunctionAttribute attribute, IEnumerable <ParameterProfile> functionParameters)
        {
            var controllerDescriptor = new ReflectedControllerDescriptor(controllerType);

            string @namespace  = String.IsNullOrEmpty(attribute.Namespace) ? controllerDescriptor.ControllerType.Namespace : attribute.Namespace;
            string name        = String.IsNullOrEmpty(attribute.Name) ? controllerDescriptor.ControllerName : attribute.Name;
            string description = attribute.Description ?? String.Empty;

            var function = new MvcActionFunction(controllerType, actionName, @namespace, name, description, this);

            if (handlePathInfo)
            {
                function.UsePathInfoForRouting();
            }

            if (functionParameters != null)
            {
                foreach (var param in functionParameters)
                {
                    function.AddParameter(param);
                }
            }

            MvcFunctionRegistry.Functions.Add(function);

            return(function);
        }
Ejemplo n.º 2
0
        public MvcFunctionBuilder RegisterAction <T>(string actionName, string functionName = null, string description = null) where T : Controller
        {
            var controllerType = typeof(T);

            Verify.That(IsController(controllerType), "Type '{0}' is not public or not its name does not have the 'Controller' ending", controllerType.FullName);

            //var methodInfo = StaticReflection.GetMethodInfo(method);

            string @namespace = null;
            string name       = null;

            if (string.IsNullOrWhiteSpace(functionName))
            {
                string controllerName = controllerType.FullName.Substring(0,
                                                                          controllerType.FullName.Length - "Controller".Length);


                if (string.Equals(actionName, "Index", StringComparison.OrdinalIgnoreCase))
                {
                    name       = actionName;
                    @namespace = controllerType.Namespace + "." + controllerName;
                }
                else
                {
                    name       = controllerName;
                    @namespace = controllerType.Namespace;
                }
            }
            else
            {
                ParseFunctionName(functionName, out @namespace, out name);
            }


            var function = new MvcActionFunction(controllerType, actionName, @namespace, name, description, this);

            MvcFunctionRegistry.Functions.Add(function);

            MvcFunctionProvider.Reload();

            return(new MvcFunctionBuilder(function));
        }