コード例 #1
0
 public ControllerDescription(Type t, AllowRoleAttribute allowRole, AllowUserAttribute allowUser, IControllerInjector injector)
 {
     this.ControllerType = t;
     this.AllowRole      = allowRole;
     this.AllowUser      = allowUser;
     this.Injector       = injector;
 }
コード例 #2
0
 public ControllerDescription(Type t, AllowRoleAttribute allowRole, AllowUserAttribute allowUser, IControllerInjector injector)
 {
     this.ControllerType = t;
     this.AllowRole = allowRole;
     this.AllowUser = allowUser;
     this.Injector = injector;
 }
コード例 #3
0
 public ActionDescription(MethodInfo methodInfo, ActionAttribute attr, AllowRoleAttribute allowRole, AllowUserAttribute allowUser)
 {
     this.MethodInfo = methodInfo;
     this.Parameters = methodInfo.GetParameters();
     this.HasReturn  = methodInfo.ReturnType != typeof(void);
     this.Attr       = attr;
     this.AllowRole  = allowRole;
     this.AllowUser  = allowUser;
 }
コード例 #4
0
 public ActionDescription(MethodInfo methodInfo, ActionAttribute attr, AllowRoleAttribute allowRole, AllowUserAttribute allowUser)
 {
     this.MethodInfo = methodInfo;
     this.Parameters = methodInfo.GetParameters();
     this.HasReturn = methodInfo.ReturnType != typeof(void);
     this.Attr = attr;
     this.AllowRole = allowRole;
     this.AllowUser = allowUser;
 }
コード例 #5
0
 public ControllerDescription(Type t, AllowRoleAttribute allowRole, AllowUserAttribute allowUser)
 {
     this.ControllerType = t;
     this.AllowRole      = allowRole;
     this.AllowUser      = allowUser;
 }
コード例 #6
0
 public ControllerDescription(Type t, AllowRoleAttribute allowRole, AllowUserAttribute allowUser)
 {
     this.ControllerType = t;
     this.AllowRole = allowRole;
     this.AllowUser = allowUser;
 }
コード例 #7
0
ファイル: InitEngine.cs プロジェクト: webxiaohua/SmartNetMVC
        /// <summary>
        /// 加载所有Controller
        /// </summary>
        private static void InitControllers()
        {
            List <ControllerDescription> controllerList = new List <ControllerDescription>();//控制器集合
            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"))
                    {
                        AllowRoleAttribute  allowRole = null;
                        AllowUserAttribute  allowUser = null;
                        IControllerInjector injector  = null;
                        if (t.GetCustomAttributes(typeof(AllowRoleAttribute), false).Length != 0)
                        {
                            allowRole = (AllowRoleAttribute)t.GetCustomAttributes(typeof(AllowRoleAttribute), false)[0];
                        }
                        if (t.GetCustomAttributes(typeof(AllowUserAttribute), false).Length != 0)
                        {
                            allowUser = (AllowUserAttribute)t.GetCustomAttributes(typeof(AllowUserAttribute), false)[0];
                        }
                        if (t.GetCustomAttributes(typeof(IControllerInjector), false).Length != 0)
                        {
                            injector = (IControllerInjector)t.GetCustomAttributes(typeof(IControllerInjector), false)[0];
                        }
                        controllerList.Add(new ControllerDescription(t, allowRole, allowUser, injector));
                    }
                }
            }
            s_ControllerNameDict = controllerList.ToDictionary(x => x.ControllerType.Name, StringComparer.OrdinalIgnoreCase);
            // 提前加载Page Controller中的所有Action方法
            s_ControllerActionDict = new Dictionary <string, ActionDescription>();
            foreach (ControllerDescription controller in controllerList)
            {
                foreach (MethodInfo m in controller.ControllerType.GetMethods(ActionBindingFlags))
                {
                    if (m.Name.EndsWith("Action"))
                    {
                        ActionAttribute    actionAttr        = m.GetMyAttribute <ActionAttribute>();
                        AllowRoleAttribute allowRole         = m.GetMyAttribute <AllowRoleAttribute>();
                        AllowUserAttribute allowUser         = m.GetMyAttribute <AllowUserAttribute>();
                        IActionInjector    injector          = m.GetMyAttribute <IActionInjector>();
                        ActionDescription  actionDescription = new ActionDescription(m, actionAttr, allowRole, allowUser, injector)
                        {
                            PageController = controller
                        };
                        s_ControllerActionDict.Add(controller.ControllerType.Name.ToLower() + "_" + m.Name.ToLower(), actionDescription);
                    }
                }
            }
        }