I have the below code currently working and it gives back a list of all public methods that return an ActionResult and the name of their respective controllers. That is:
[{Controller = "ControllerName", Action = "ActionName"}, {...}, {...} ...]
I am trying to figure out how I can tweak this to get the name of all action results and their respective controller objects, like this:
[{Controller = {ControllerObject}, Action = "ActionName"}, {...}, {...} ...]
Anyone have any idea how this might be accomplished?
Assembly asm = Assembly.GetAssembly(typeof(MyDLL.MvcApplication));
var controllerActionList = asm.GetTypes()
.Where(type => typeof(Controller).IsAssignableFrom(type))
.SelectMany(type => type.GetMethods())
.Where(
m => m.IsPublic && m.ReturnType.Name == "ActionResult")
.Select(x => new { Controller = x.DeclaringType.Name, Action = x.Name })
.ToList();
Aucun commentaire:
Enregistrer un commentaire