Skip to content

Instantly share code, notes, and snippets.

@johnsheehan
Created March 12, 2010 22:53
Show Gist options
  • Save johnsheehan/330894 to your computer and use it in GitHub Desktop.
Save johnsheehan/330894 to your computer and use it in GitHub Desktop.
var assembly = Assembly.GetCallingAssembly();
var actionMethods = assembly.GetTypes()
// Find all non abstract classes of type Controller and whose names end with "Controller"
.Where(x => x.IsClass && !x.IsAbstract && x.IsSubclassOf(typeof(TwilioController)) && x.Name.EndsWith("Controller"))
// Find all public methods from those controller classes
.SelectMany(x => x.GetMethods().Where(m => m.DeclaringType.Name == x.Name), (x, y) => new { Controller = x.Name.Substring(0, x.Name.Length - 10), Method = y.Name });
foreach (var action in actionMethods) {
routes.MapRoute(action.Method, action.Method, new { controller = action.Controller, action = action.Method });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment