Example #1
0
        /// <summary>
        /// 获取程序集下的所有Action
        /// </summary>
        /// <returns></returns>
        public List<ActionPermission> GetAllActionByAssembly()
        {

            var result = new List<ActionPermission>();

            var types = Assembly.Load("General").GetTypes();

            foreach (var type in types)
            {
                if (type.BaseType.Name == "BaseController")//如果是Controller
                {
                    var members = type.GetMethods();
                    var Properties = type.GetProperties();
                    //object[] attrs = Properties.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
                    //if (attrs.Length > 0)
                    //    ap.Description = (attrs[0] as System.ComponentModel.DescriptionAttribute).Description;

                    foreach (var member in members)
                    {

                        if (member.ReturnType.Name == "ActionResult")//如果是Action
                        {
                            var ap = new ActionPermission();

                            ap.ActionName = member.Name;
                            ap.ControllerName = member.DeclaringType.Name.Substring(0, member.DeclaringType.Name.Length - 10); // 去掉“Controller”后缀
                            //{Name = "HomeController" FullName = "General.Areas.Backstage.Controllers.HomeController"}
                            Regex rg = new Regex("(?<=(Areas.))[\\S]+(?=(.Controllers))", RegexOptions.Multiline | RegexOptions.Singleline);

                            ap.AreaName = rg.Match(member.DeclaringType.FullName).Value;
                            string Description = "";
                            object[] attrs = member.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
                            if (attrs.Length > 0)
                                Description = (attrs[0] as System.ComponentModel.DescriptionAttribute).Description;

                            string[] DescriptionArr = Description.Split('/');
                            for (int i = 0; i < DescriptionArr.Length; i++)
                            {
                                switch (i)
                                {
                                    case 0:
                                        ap.FirstPath = DescriptionArr[0];
                                        ap.FirstPath_Spell = ChineseToSpell.ConvertToAllSpell(DescriptionArr[0]);
                                        break;
                                    case 1:
                                        ap.SecoundPath = DescriptionArr[1];
                                        ap.SecoundPath_Spell = ChineseToSpell.ConvertToAllSpell(DescriptionArr[1]);
                                        break;
                                    case 2:
                                        ap.Description = DescriptionArr[2];
                                        ap.Description_Spell = ChineseToSpell.ConvertToAllSpell(DescriptionArr[2]);
                                        break;
                                    default:
                                        break;
                                }
                            }

                            result.Add(ap);
                        }
                    }
                }
            }
            return result;
        }
Example #2
0
        /// <summary>
        /// 获取程序集下的所有Action
        /// </summary>
        /// <returns></returns>
        public List <ActionPermission> GetAllActionByAssembly()
        {
            var result = new List <ActionPermission>();

            var types = Assembly.Load("General").GetTypes();

            foreach (var type in types)
            {
                if (type.BaseType.Name == "BaseController")//如果是Controller
                {
                    var members    = type.GetMethods();
                    var Properties = type.GetProperties();
                    //object[] attrs = Properties.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
                    //if (attrs.Length > 0)
                    //    ap.Description = (attrs[0] as System.ComponentModel.DescriptionAttribute).Description;

                    foreach (var member in members)
                    {
                        if (member.ReturnType.Name == "ActionResult")//如果是Action
                        {
                            var ap = new ActionPermission();

                            ap.ActionName     = member.Name;
                            ap.ControllerName = member.DeclaringType.Name.Substring(0, member.DeclaringType.Name.Length - 10); // 去掉“Controller”后缀
                            //{Name = "HomeController" FullName = "General.Areas.Backstage.Controllers.HomeController"}
                            Regex rg = new Regex("(?<=(Areas.))[\\S]+(?=(.Controllers))", RegexOptions.Multiline | RegexOptions.Singleline);

                            ap.AreaName = rg.Match(member.DeclaringType.FullName).Value;
                            string   Description = "";
                            object[] attrs       = member.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
                            if (attrs.Length > 0)
                            {
                                Description = (attrs[0] as System.ComponentModel.DescriptionAttribute).Description;
                            }

                            string[] DescriptionArr = Description.Split('/');
                            for (int i = 0; i < DescriptionArr.Length; i++)
                            {
                                switch (i)
                                {
                                case 0:
                                    ap.FirstPath       = DescriptionArr[0];
                                    ap.FirstPath_Spell = ChineseToSpell.ConvertToAllSpell(DescriptionArr[0]);
                                    break;

                                case 1:
                                    ap.SecoundPath       = DescriptionArr[1];
                                    ap.SecoundPath_Spell = ChineseToSpell.ConvertToAllSpell(DescriptionArr[1]);
                                    break;

                                case 2:
                                    ap.Description       = DescriptionArr[2];
                                    ap.Description_Spell = ChineseToSpell.ConvertToAllSpell(DescriptionArr[2]);
                                    break;

                                default:
                                    break;
                                }
                            }

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