Skip to content

Instantly share code, notes, and snippets.

View johnsheehan's full-sized avatar

John Sheehan johnsheehan

  • White Bear Lake, MN
View GitHub Profile
public class HomeController : TwilioController
{
// /StartPhoneCall
public void StartPhoneCall() {
Say("Thank you for calling " + Called);
Say("Hello world!", 1, Voice.Man, Language.English);
Play("http://example.com", 1);
Gather(30,
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 });
}