Esempio n. 1
0
        /// <summary>
        /// 编译函数
        /// </summary>
        /// <param name="controllerType">控制器类型</param>
        /// <param name="method">方法信息</param>
        /// <param name="baseRouted">控制器路由标记</param>
        private IRoute[] ComplieFunction(Type controllerType, MethodInfo method, RoutedAttribute baseRouted)
        {
            var routeds = method.GetCustomAttributes(this.routed, false);

            if (routeds.Length <= 0)
            {
                return(null);
            }

            var             ret = new List <IRoute>();
            RoutedAttribute routed;

            for (var i = 0; i < routeds.Length; i++)
            {
                routed = routeds[i] as RoutedAttribute;

                //如果没有给定方法路由名则默认提供
                if (string.IsNullOrEmpty(routed.Path))
                {
                    routed.Path = ClassOrFunctionNameToRouteName(method.Name);
                }

                //如果是包含scheme完整的uri那么则忽略来自控制器提供的uri
                //这里的所有的开头都不允许出现‘/’
                var path = routed.Path.TrimStart('/');
                if (baseRouted != null && !HasScheme(routed.Path))
                {
                    //如果开发者提供了控制器的路由配置,那么将会合并控制器路由的全局部分
                    var index = baseRouted.Path.LastIndexOf("://");
                    if (index != -1 && (index + 3) == baseRouted.Path.Length)
                    {
                        path = baseRouted.Path + path;
                    }
                    else
                    {
                        path = baseRouted.Path.TrimEnd('/') + "/" + path;
                    }
                }

                // 检查控制器内是否重复编译
                if (controllerFuncBuildRecord.ContainsKey(path + "$" + method.Name))
                {
                    continue;
                }
                controllerFuncBuildRecord.Add(path + "$" + method.Name, true);

                // 检查全局是否重复编译
                CheckRepeat(path, controllerType, method);

                var route = router.Reg(path, controllerType, method.Name);

                //编译标记中的属性路由中的配置到路由条目中
                ComplieOptions(route, routed);

                ret.Add(route);
            }

            return(ret.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// 编译函数
        /// </summary>
        /// <param name="method"></param>
        /// <param name="baseRouted"></param>
        protected IRoute ComplieFunction(Type type, MethodInfo method, Routed baseRouted)
        {
            object[] routeds = method.GetCustomAttributes(this.routed, false);
            if (routeds.Length <= 0)
            {
                return(null);
            }

            Routed routed = routeds[0] as Routed;

            if (routed == null)
            {
                return(null);
            }

            //如果是包含scheme完整的uri那么则忽略来自控制器提供的uri
            //这里的所有的开头都不允许出现‘/’
            string path = routed.Path.TrimStart('/');

            if (baseRouted != null && !HasScheme(routed.Path))
            {
                //如果开发者提供了控制器的路由配置,那么将会合并控制器路由的全局部分
                int index = baseRouted.Path.LastIndexOf("://");
                if (index != -1 && (index + 3) == baseRouted.Path.Length)
                {
                    path = baseRouted.Path + path;
                }
                else
                {
                    path = baseRouted.Path.TrimEnd('/') + "/" + path;
                }
            }

            IRoute route = router.Reg(path, type, method.Name);

            //编译标记中的属性路由中的配置到路由条目中
            ComplieOptions(route, routed);

            return(route);
        }