Exemple #1
0
        private static IList <ActionPermission> GetAllActionByAssembly()
        {
            List <ActionPermission> actionPermissions = new List <ActionPermission>();
            IEnumerable <Type>      types             = ((IEnumerable <Type>)Assembly.Load("Himall.Web").GetTypes()).Where((Type a) => {
                if (a.BaseType == null)
                {
                    return(false);
                }
                return(a.BaseType.Name == "BaseSellerController");
            });

            foreach (Type type in types)
            {
                MethodInfo[] methods = type.GetMethods();
                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo methodInfo = methods[i];
                    if (methodInfo.ReturnType.Name == "ActionResult" || methodInfo.ReturnType.Name == "JsonResult")
                    {
                        ActionPermission actionPermission = new ActionPermission()
                        {
                            ActionName     = methodInfo.Name,
                            ControllerName = methodInfo.DeclaringType.Name.Substring(0, methodInfo.DeclaringType.Name.Length - 10)
                        };
                        object[] customAttributes = methodInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
                        if (customAttributes.Length > 0)
                        {
                            actionPermission.Description = (customAttributes[0] as DescriptionAttribute).Description;
                        }
                        actionPermissions.Add(actionPermission);
                    }
                }
            }
            return(actionPermissions);
        }
Exemple #2
0
        private static IList <ActionPermission> GetAllActionByAssembly()
        {
            var result = new List <ActionPermission>();
            var types  = Assembly.Load("Himall.Web").GetTypes().Where(a => a.BaseType != null && a.BaseType.Name == "BaseAdminController");

            foreach (var type in types)
            {
                var members = type.GetMethods();
                foreach (var member in members)
                {
                    if (member.ReturnType.Name == "ActionResult" || member.ReturnType.Name == "JsonResult" || (member.ReturnType.FullName != null && member.ReturnType.FullName.Contains("ActionResult")))//如果是Action
                    {
                        var ap = new ActionPermission();

                        ap.ActionName     = member.Name;
                        ap.ControllerName = member.DeclaringType.Name.Substring(0, member.DeclaringType.Name.Length - 10); // 去掉“Controller”后缀

                        object[] attrs = member.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
                        if (attrs.Length > 0)
                        {
                            ap.Description = (attrs[0] as System.ComponentModel.DescriptionAttribute).Description;
                        }

                        result.Add(ap);
                    }
                }
            }
            return(result);
        }