public static List<string> GetALLPageByReflection()
{
List<string> actions = new List<string>();
var asm = System.Reflection.Assembly.GetExecutingAssembly();
System.Collections.Generic.List<Type> typeList = new List<Type>();
var types = asm.GetTypes();
foreach (Type type in types)
{
string s = type.FullName.ToLower();
if (type.Name.StartsWith("AccountCont")) continue;
if (s.StartsWith("开始字符串") && s.EndsWith("结束字符串"))
typeList.Add(type);
}
typeList.Sort(delegate(Type type1, Type type2) { return type1.FullName.CompareTo(type2.FullName); });
foreach (Type type in typeList)
{
//Response.Write(type.Name.Replace("Controller","") + "<br/>\n");
System.Reflection.MemberInfo[] members = type.FindMembers(System.Reflection.MemberTypes.Method,
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Static |
System.Reflection.BindingFlags.NonPublic | //【位屏蔽】
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.DeclaredOnly,
Type.FilterName, "*");
foreach (var m in members)
{
if (m.DeclaringType.Attributes.HasFlag(System.Reflection.TypeAttributes.Public) != true)
continue;
string controller = type.Name.Replace("Controller", "");
string action = m.Name;
string url = "/" + controller + "/" + action;
if (!action.Contains("<"))
{
actions.Add(url);
}
}
}
return actions;
}
来自小聪ssc