当前位置:编程学习 > C#/ASP.NET >>

如果获取工程中所有Controller 秒结

如果获取工程中所有Controller 秒结

解决马上结贴 --------------------编程问答-------------------- --------------------编程问答-------------------- 这个真不知道,先帮楼主顶下,自己也学习。 --------------------编程问答-------------------- 呵呵 还是反射
方便后人
public IList<ActionPermission> GetAllActionByAssembly()
        {
            var result = new List<ActionPermission>();
            var types = Assembly.Load("Demo.HIS.MVC").GetTypes();
            foreach (var type in types)
            {
                if (type.BaseType.Name == "BaseController")  
                {
                    var members = type.GetMethods();
                    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);            
                            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;
        }


大家可以谈谈MVC +Form表单验证。

--------------------编程问答-------------------- 你说取出来放到 单独一个工程里面?
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,