예제 #1
0
 public ActionDescription(MethodInfo m, ActionAttribute atrr)
     : base(m)
 {
     this.MethodInfo = m;
     this.Attr = atrr;
     this.Parameters = m.GetParameters();
     this.HasReturn = m.ReturnType != ReflectionHelper.VoidType;
 }
예제 #2
0
 public ActionDescription(MethodInfo m, ActionAttribute atrr)
     : base(m)
 {
     this.MethodInfo = m;
     this.Attr       = atrr;
     this.Parameters = m.GetParameters();
     this.HasReturn  = m.ReturnType != ReflectionHelper.VoidType;
 }
예제 #3
0
        /// <summary>
        /// 加载所有的Controller
        /// </summary>
        private static void InitControllers()
        {
            BaseActionHandlerFactory[] baseActionHandlerFactoryList = GetConfigBaseActionHandlerFactory();

            List <ControllerDescription> serviceControllerList = new List <ControllerDescription>(1024);
            var pageControllerList = new List <ControllerDescription>(1024);

            ICollection assemblies = BuildManager.GetReferencedAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                // 过滤以【System】开头的程序集,加快速度
                if (assembly.FullName.StartsWith("System", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                foreach (Type t in assembly.GetExportedTypes())
                {
                    if (t.IsClass == false)
                    {
                        continue;
                    }

                    if (t.Name.EndsWith("Controller"))
                    {
                        pageControllerList.Add(new ControllerDescription(t));
                    }

                    for (int i = 0; i < baseActionHandlerFactoryList.Length; i++)
                    {
                        if (baseActionHandlerFactoryList[i].TypeIsService(t))
                        {
                            serviceControllerList.Add(new ControllerDescription(t));
                            break;
                        }
                    }
                }
            }

            // 用于Ajax or Service 调用的Action信息则采用延迟加载的方式。

            s_ServiceFullNameDict = serviceControllerList.ToDictionary(x => x.ControllerType.FullName, StringComparer.OrdinalIgnoreCase);

            s_ServiceShortNameDict = new Dictionary <string, ControllerDescription>(s_ServiceFullNameDict.Count, StringComparer.OrdinalIgnoreCase);
            foreach (ControllerDescription description in serviceControllerList)
            {
                try
                {
                    s_ServiceShortNameDict.Add(description.ControllerType.Name, description);
                }
                catch (ArgumentException)
                {
                    // 如果遇到已存在的KEY,把原先存放的项也设置为 null,便于查找时返回 null
                    s_ServiceShortNameDict[description.ControllerType.Name] = null;
                }
            }



            // 提前加载Page Controller中的所有Action方法
            s_PageActionDict = new Dictionary <string, ActionDescription>(4096, StringComparer.OrdinalIgnoreCase);

            foreach (ControllerDescription controller in pageControllerList)
            {
                foreach (MethodInfo m in controller.ControllerType.GetMethods(ActionBindingFlags))
                {
                    PageUrlAttribute[] pageUrlAttrs = m.GetMyAttributes <PageUrlAttribute>();
                    ActionAttribute    actionAttr   = m.GetMyAttribute <ActionAttribute>();

                    if (pageUrlAttrs.Length > 0 && actionAttr != null)
                    {
                        ActionDescription actionDescription =
                            new ActionDescription(m, actionAttr)
                        {
                            PageController = controller
                        };

                        foreach (PageUrlAttribute attr in pageUrlAttrs)
                        {
                            if (string.IsNullOrEmpty(attr.Url) == false)
                            {
                                s_PageActionDict.Add(attr.Url, actionDescription);
                            }
                        }
                    }
                }
            }
        }