private static HttpRouteInformation CacheRouteInternal(IHttpRoute route) { var httpRoute = route as HttpRoute; if (httpRoute == null) { throw new InvalidOperationException("Invalid route"); } if (httpRoute.Handler != null) { throw new InvalidOperationException("Cannot copy route with handler: " + route.RouteTemplate); } var routeInformation = new HttpRouteInformation { Constraints = httpRoute.Constraints.ToDictionary(x => x.Key, x => x.Value), DataTokens = httpRoute.DataTokens.ToDictionary(x => x.Key, x => x.Value), Defaults = httpRoute.Defaults.ToDictionary(x => x.Key, x => x.Value), RouteTemplate = httpRoute.RouteTemplate }; object value; if (routeInformation.DataTokens.TryGetValue(ActionsDataTokenKey, out value)) { var descriptors = (HttpActionDescriptor[])value; var descriptorInformations = new HttpActionDescriptorInformation[descriptors.Length]; for (var index = 0; index < descriptors.Length; index++) { var descriptor = (ReflectedHttpActionDescriptor)descriptors[index]; var methodInfo = descriptor.MethodInfo; var controllerName = descriptor.ControllerDescriptor.ControllerName; var controllerType = descriptor.ControllerDescriptor.ControllerType; var properties = descriptor.Properties.ToDictionary(x => x.Key, x => x.Value); descriptorInformations[index] = new HttpActionDescriptorInformation { MethodInfo = methodInfo, ControllerName = controllerName, ControllerType = controllerType, Properties = properties }; } routeInformation.DataTokens.Remove(ActionsDataTokenKey); routeInformation.DataTokens[InfoDataTokenKey] = descriptorInformations; } return(routeInformation); }
private static HttpRouteInformation CacheRouteInternal(IHttpRoute route) { var httpRoute = route as HttpRoute; if (httpRoute == null) throw new InvalidOperationException("Invalid route"); if (httpRoute.Handler != null) throw new InvalidOperationException("Cannot copy route with handler: " + route.RouteTemplate); var routeInformation = new HttpRouteInformation { Constraints = httpRoute.Constraints.ToDictionary(x => x.Key, x => x.Value), DataTokens = httpRoute.DataTokens.ToDictionary(x => x.Key, x => x.Value), Defaults = httpRoute.Defaults.ToDictionary(x => x.Key, x => x.Value), RouteTemplate = httpRoute.RouteTemplate }; object value; if (routeInformation.DataTokens.TryGetValue(ActionsDataTokenKey, out value)) { var descriptors = (HttpActionDescriptor[])value; var descriptorInformations = new HttpActionDescriptorInformation[descriptors.Length]; for (var index = 0; index < descriptors.Length; index++) { var descriptor = (ReflectedHttpActionDescriptor)descriptors[index]; var methodInfo = descriptor.MethodInfo; var controllerName = descriptor.ControllerDescriptor.ControllerName; var controllerType = descriptor.ControllerDescriptor.ControllerType; var properties = descriptor.Properties.ToDictionary(x => x.Key, x => x.Value); descriptorInformations[index] = new HttpActionDescriptorInformation { MethodInfo = methodInfo, ControllerName = controllerName, ControllerType = controllerType, Properties = properties }; } routeInformation.DataTokens.Remove(ActionsDataTokenKey); routeInformation.DataTokens[InfoDataTokenKey] = descriptorInformations; } return routeInformation; }