Пример #1
0
        public static void RegistController(Type t)
        {
            if (!t.GetInterfaces().Contains(typeof(IMyController)))
            {
                return;
            }
            //dynamic controller = Activator.CreateInstance(t);
            //自动注册该类的所有方法
            string controllername    = t.Name.ToLower();
            ControllerDescription cd = new ControllerDescription(t);

            if (s_ServiceCommandDict.ContainsKey(controllername))
            {
                return;
            }

            s_ServiceCommandDict.Add(controllername, cd);
            foreach (MethodInfo m in cd.ControllerType.GetMethods(ActionBindingFlags))
            {
                ActionAttribute actionAttr = m.GetMyAttribute <ActionAttribute>();
                if (actionAttr != null)
                {
                    ActionDescription actionDescription = new ActionDescription(m, actionAttr)
                    {
                        PageController = cd
                    };
                    string actionname = m.Name.ToLower();
                    s_PageActionDict.Add(controllername + "/" + actionname, actionDescription);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 根据要调用的controller名返回对应的Controller
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        private static ControllerDescription GetServiceController(string controller)
        {
            if (controller == "")
            {
                throw new ArgumentNullException("controller");
            }

            ControllerDescription description = null;

            // 查找类型的方式:如果有点号,则按全名来查找(包含命名空间),否则只看类型名称。
            // 如果有多个类型的名称相同,必须用完整的命名空间来调用,否则不能定位Controller
            s_ServiceCommandDict.TryGetValue(controller, out description);

            return(description);
        }