Skip to content

Instantly share code, notes, and snippets.

@prettycode
Created May 25, 2013 07:19
Show Gist options
  • Save prettycode/5648250 to your computer and use it in GitHub Desktop.
Save prettycode/5648250 to your computer and use it in GitHub Desktop.
Count the number of distinct Controller actions in an ASP.NET MVC application.
var actionCount = typeof(/*Some Controller Type In Your MVC App*/)
.Assembly.GetTypes()
.Where(t => typeof(Controller).IsAssignableFrom(t))
.Where(t => t.Namespace.StartsWith("AwesomeProduct.Web"))
.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Instance))
.Where(m => typeof(ActionResult).IsAssignableFrom(m.ReturnType))
.Where(m => !m.IsAbstract)
.Where(m => m.GetCustomAttribute<NonActionAttribute>() == null)
.Count();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment