public void Add(MvcRouteInfo routeInfo) { if (!this.routes.TryGetValue(routeInfo.Url, out var urlRouteList)) { urlRouteList = new List <MvcRouteInfo>(); this.routes.Add(routeInfo.Url, urlRouteList); } // Validate if (urlRouteList.Any(q => q.Verb == routeInfo.Verb)) { throw new ArgumentException("There is already another route with this Url and Verb"); } urlRouteList.Add(routeInfo); }
private void ParseController(Type controllerType) { var methods = controllerType.GetMethods(); foreach (var method in methods) { // Must be decorated with RouteAttribute var routeAttribute = method.GetCustomAttribute <RouteAttribute>(); if (routeAttribute == null) { continue; } // Check if there is any verb var verbAttribute = method.GetCustomAttribute <HttpVerbAttribute>(); var routeInfo = new MvcRouteInfo( routeAttribute.Route, verbAttribute?.Verb, controllerType, method); this.Routes.Add(routeInfo); } }